Copy based on last modified date of filesHow to copy only new files AND only those that are modified after a...
What method can I use to design a dungeon difficult enough that the PCs can't make it through without killing them?
GFCI outlets - can they be repaired? Are they really needed at the end of a circuit?
Is it logically or scientifically possible to artificially send energy to the body?
How does a predictive coding aid in lossless compression?
Can we compute the area of a quadrilateral with one right angle when we only know the lengths of any three sides?
Why would the Red Woman birth a shadow if she worshipped the Lord of the Light?
Expand and Contract
Extract rows of a table, that include less than x NULLs
What mechanic is there to disable a threat instead of killing it?
Avoiding direct proof while writing proof by induction
Ambiguity in the definition of entropy
Why didn't Boeing produce its own regional jet?
How to prevent "they're falling in love" trope
How writing a dominant 7 sus4 chord in RNA ( Vsus7 chord in the 1st inversion)
Is it inappropriate for a student to attend their mentor's dissertation defense?
Bullying boss launched a smear campaign and made me unemployable
Why no variance term in Bayesian logistic regression?
Can the Meissner effect explain very large floating structures?
Can a virus destroy the BIOS of a modern computer?
Why is consensus so controversial in Britain?
What is the idiomatic way to say "clothing fits"?
Determining Impedance With An Antenna Analyzer
Im going to France and my passport expires June 19th
Why didn't Miles's spider sense work before?
Copy based on last modified date of files
How to copy only new files AND only those that are modified after a certain date?File copy, based on sizeBatch File:List all files of a type, rename files, flatten the directoryRobocopy Log File Meaning of New File, New DirChanging last modified date or time via PowerShellFull server backup using powershell scriptMerging Scripts…Wrong Type of File-Object (Maybe)?Robocopy (win) | Ensuring Integrity | Source/Destination “size” NOT identical (whole drives)Copy only if destination was modified on a specific dateYoutube-DL: Date Modified
I want to copy from below source dir to the desired destination as shown below.
Source dir:
--Dummy
----dirA (contain files last modified 2/7/2015)
----dirB (contain files last modified 3/7/2015)
----dirC (contain files last modified 18/7/2015)
----dirD (contain files last modified 18/7/2015)
----dirE (contain files last modified 2/7/2015)
each dir
above in Dummy contain files with specific last modified date
Destination dir suppose to looks like this:
--Dummy2015-07-2
----dirA (contain files last modified 2/7/2015)
----dirE (contain files last modified 2/7/2015)
--Dummy2015-07-3
----dirB (contain files last modified 3/7/2015)
--Dummy2015-07-18
----dirC (contain files last modified 18/7/2015)
----dirD (contain files last modified 18/7/2015)
so far, by referring to here, i managed to come out something like this:
$sourcePath = 'c:/dummy'
$destPath = 'e:/dummy'
Get-ChildItem -recurse -Path $sourcePath | Group {$_.LastWriteTime.ToString("yyyy-MM-dd")} |
Foreach-Object{
$folder = New-Item -Path "$($destPath)$($_.Name)" -ItemType Directory -Force
$_.Group | Where-Object { -not (Test-Path "$($folder.FullName)$($_.Name)") } | Copy-Item -Destination $folder.FullName
}
but the above code directly copy the files within the dir of source dummy which make destination becomes like this:
--Dummy2015-07-2
----(all files from dirA & dir E)
--Dummy2015-07-3
----(all files from dirB)
--Dummy2015-07-18
----(all files from dirC & dirD)
(if possible, would like to do this using robocopy)
powershell robocopy
bumped to the homepage by Community♦ 1 hour ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I want to copy from below source dir to the desired destination as shown below.
Source dir:
--Dummy
----dirA (contain files last modified 2/7/2015)
----dirB (contain files last modified 3/7/2015)
----dirC (contain files last modified 18/7/2015)
----dirD (contain files last modified 18/7/2015)
----dirE (contain files last modified 2/7/2015)
each dir
above in Dummy contain files with specific last modified date
Destination dir suppose to looks like this:
--Dummy2015-07-2
----dirA (contain files last modified 2/7/2015)
----dirE (contain files last modified 2/7/2015)
--Dummy2015-07-3
----dirB (contain files last modified 3/7/2015)
--Dummy2015-07-18
----dirC (contain files last modified 18/7/2015)
----dirD (contain files last modified 18/7/2015)
so far, by referring to here, i managed to come out something like this:
$sourcePath = 'c:/dummy'
$destPath = 'e:/dummy'
Get-ChildItem -recurse -Path $sourcePath | Group {$_.LastWriteTime.ToString("yyyy-MM-dd")} |
Foreach-Object{
$folder = New-Item -Path "$($destPath)$($_.Name)" -ItemType Directory -Force
$_.Group | Where-Object { -not (Test-Path "$($folder.FullName)$($_.Name)") } | Copy-Item -Destination $folder.FullName
}
but the above code directly copy the files within the dir of source dummy which make destination becomes like this:
--Dummy2015-07-2
----(all files from dirA & dir E)
--Dummy2015-07-3
----(all files from dirB)
--Dummy2015-07-18
----(all files from dirC & dirD)
(if possible, would like to do this using robocopy)
powershell robocopy
bumped to the homepage by Community♦ 1 hour ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I want to copy from below source dir to the desired destination as shown below.
Source dir:
--Dummy
----dirA (contain files last modified 2/7/2015)
----dirB (contain files last modified 3/7/2015)
----dirC (contain files last modified 18/7/2015)
----dirD (contain files last modified 18/7/2015)
----dirE (contain files last modified 2/7/2015)
each dir
above in Dummy contain files with specific last modified date
Destination dir suppose to looks like this:
--Dummy2015-07-2
----dirA (contain files last modified 2/7/2015)
----dirE (contain files last modified 2/7/2015)
--Dummy2015-07-3
----dirB (contain files last modified 3/7/2015)
--Dummy2015-07-18
----dirC (contain files last modified 18/7/2015)
----dirD (contain files last modified 18/7/2015)
so far, by referring to here, i managed to come out something like this:
$sourcePath = 'c:/dummy'
$destPath = 'e:/dummy'
Get-ChildItem -recurse -Path $sourcePath | Group {$_.LastWriteTime.ToString("yyyy-MM-dd")} |
Foreach-Object{
$folder = New-Item -Path "$($destPath)$($_.Name)" -ItemType Directory -Force
$_.Group | Where-Object { -not (Test-Path "$($folder.FullName)$($_.Name)") } | Copy-Item -Destination $folder.FullName
}
but the above code directly copy the files within the dir of source dummy which make destination becomes like this:
--Dummy2015-07-2
----(all files from dirA & dir E)
--Dummy2015-07-3
----(all files from dirB)
--Dummy2015-07-18
----(all files from dirC & dirD)
(if possible, would like to do this using robocopy)
powershell robocopy
I want to copy from below source dir to the desired destination as shown below.
Source dir:
--Dummy
----dirA (contain files last modified 2/7/2015)
----dirB (contain files last modified 3/7/2015)
----dirC (contain files last modified 18/7/2015)
----dirD (contain files last modified 18/7/2015)
----dirE (contain files last modified 2/7/2015)
each dir
above in Dummy contain files with specific last modified date
Destination dir suppose to looks like this:
--Dummy2015-07-2
----dirA (contain files last modified 2/7/2015)
----dirE (contain files last modified 2/7/2015)
--Dummy2015-07-3
----dirB (contain files last modified 3/7/2015)
--Dummy2015-07-18
----dirC (contain files last modified 18/7/2015)
----dirD (contain files last modified 18/7/2015)
so far, by referring to here, i managed to come out something like this:
$sourcePath = 'c:/dummy'
$destPath = 'e:/dummy'
Get-ChildItem -recurse -Path $sourcePath | Group {$_.LastWriteTime.ToString("yyyy-MM-dd")} |
Foreach-Object{
$folder = New-Item -Path "$($destPath)$($_.Name)" -ItemType Directory -Force
$_.Group | Where-Object { -not (Test-Path "$($folder.FullName)$($_.Name)") } | Copy-Item -Destination $folder.FullName
}
but the above code directly copy the files within the dir of source dummy which make destination becomes like this:
--Dummy2015-07-2
----(all files from dirA & dir E)
--Dummy2015-07-3
----(all files from dirB)
--Dummy2015-07-18
----(all files from dirC & dirD)
(if possible, would like to do this using robocopy)
powershell robocopy
powershell robocopy
edited May 23 '17 at 12:41
Community♦
1
1
asked Jul 28 '15 at 4:35
Z.VZ.V
1073
1073
bumped to the homepage by Community♦ 1 hour ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 1 hour ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Does dirA contain only files modified on 2015.07.02? Or does it contain files modified before that? In my answer, I assume the prior. I will also assume each folder only has files, or has folders that you want to associate with that same folder (i.e. you will not move them out of their parent folder).
Below is the code that should work. Fill in the first 2 variables.
And hey, it uses robocopy
! :)
$PathToRootOfDummy = "C:pathtodummyroot"
$PathToReplacementPrefix = "C:pathtodummy_new-" # date goes after the '-'
Get-ChildItem $PathToRootOfDummy | Where-Object {$_.PSISContainer -eq $true} | ForEach-Object {
$nf = "$PathToReplacementPrefix$($(Get-ChildItem -Path $PathToRootOfDummy$($_.Name) | Where { ! $_.PSIsContainer} )[0].LastWriteTime.tostring("yyyy-MM-dd"))"
mkdir $nf
robocopy -s -e $PathToRootOfDummy$_ $nf
}
Although... I would recommend usingCopy-Item
instead, since we are doing this inPowershell
anyway.
– nehcsivart
Aug 26 '15 at 5:51
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f946174%2fcopy-based-on-last-modified-date-of-files%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Does dirA contain only files modified on 2015.07.02? Or does it contain files modified before that? In my answer, I assume the prior. I will also assume each folder only has files, or has folders that you want to associate with that same folder (i.e. you will not move them out of their parent folder).
Below is the code that should work. Fill in the first 2 variables.
And hey, it uses robocopy
! :)
$PathToRootOfDummy = "C:pathtodummyroot"
$PathToReplacementPrefix = "C:pathtodummy_new-" # date goes after the '-'
Get-ChildItem $PathToRootOfDummy | Where-Object {$_.PSISContainer -eq $true} | ForEach-Object {
$nf = "$PathToReplacementPrefix$($(Get-ChildItem -Path $PathToRootOfDummy$($_.Name) | Where { ! $_.PSIsContainer} )[0].LastWriteTime.tostring("yyyy-MM-dd"))"
mkdir $nf
robocopy -s -e $PathToRootOfDummy$_ $nf
}
Although... I would recommend usingCopy-Item
instead, since we are doing this inPowershell
anyway.
– nehcsivart
Aug 26 '15 at 5:51
add a comment |
Does dirA contain only files modified on 2015.07.02? Or does it contain files modified before that? In my answer, I assume the prior. I will also assume each folder only has files, or has folders that you want to associate with that same folder (i.e. you will not move them out of their parent folder).
Below is the code that should work. Fill in the first 2 variables.
And hey, it uses robocopy
! :)
$PathToRootOfDummy = "C:pathtodummyroot"
$PathToReplacementPrefix = "C:pathtodummy_new-" # date goes after the '-'
Get-ChildItem $PathToRootOfDummy | Where-Object {$_.PSISContainer -eq $true} | ForEach-Object {
$nf = "$PathToReplacementPrefix$($(Get-ChildItem -Path $PathToRootOfDummy$($_.Name) | Where { ! $_.PSIsContainer} )[0].LastWriteTime.tostring("yyyy-MM-dd"))"
mkdir $nf
robocopy -s -e $PathToRootOfDummy$_ $nf
}
Although... I would recommend usingCopy-Item
instead, since we are doing this inPowershell
anyway.
– nehcsivart
Aug 26 '15 at 5:51
add a comment |
Does dirA contain only files modified on 2015.07.02? Or does it contain files modified before that? In my answer, I assume the prior. I will also assume each folder only has files, or has folders that you want to associate with that same folder (i.e. you will not move them out of their parent folder).
Below is the code that should work. Fill in the first 2 variables.
And hey, it uses robocopy
! :)
$PathToRootOfDummy = "C:pathtodummyroot"
$PathToReplacementPrefix = "C:pathtodummy_new-" # date goes after the '-'
Get-ChildItem $PathToRootOfDummy | Where-Object {$_.PSISContainer -eq $true} | ForEach-Object {
$nf = "$PathToReplacementPrefix$($(Get-ChildItem -Path $PathToRootOfDummy$($_.Name) | Where { ! $_.PSIsContainer} )[0].LastWriteTime.tostring("yyyy-MM-dd"))"
mkdir $nf
robocopy -s -e $PathToRootOfDummy$_ $nf
}
Does dirA contain only files modified on 2015.07.02? Or does it contain files modified before that? In my answer, I assume the prior. I will also assume each folder only has files, or has folders that you want to associate with that same folder (i.e. you will not move them out of their parent folder).
Below is the code that should work. Fill in the first 2 variables.
And hey, it uses robocopy
! :)
$PathToRootOfDummy = "C:pathtodummyroot"
$PathToReplacementPrefix = "C:pathtodummy_new-" # date goes after the '-'
Get-ChildItem $PathToRootOfDummy | Where-Object {$_.PSISContainer -eq $true} | ForEach-Object {
$nf = "$PathToReplacementPrefix$($(Get-ChildItem -Path $PathToRootOfDummy$($_.Name) | Where { ! $_.PSIsContainer} )[0].LastWriteTime.tostring("yyyy-MM-dd"))"
mkdir $nf
robocopy -s -e $PathToRootOfDummy$_ $nf
}
answered Aug 26 '15 at 5:50
nehcsivartnehcsivart
428311
428311
Although... I would recommend usingCopy-Item
instead, since we are doing this inPowershell
anyway.
– nehcsivart
Aug 26 '15 at 5:51
add a comment |
Although... I would recommend usingCopy-Item
instead, since we are doing this inPowershell
anyway.
– nehcsivart
Aug 26 '15 at 5:51
Although... I would recommend using
Copy-Item
instead, since we are doing this in Powershell
anyway.– nehcsivart
Aug 26 '15 at 5:51
Although... I would recommend using
Copy-Item
instead, since we are doing this in Powershell
anyway.– nehcsivart
Aug 26 '15 at 5:51
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f946174%2fcopy-based-on-last-modified-date-of-files%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown