0

Here s the .bat I'm using curently:

for %%I in  (I:\ETOS\00-5-1-WA-1
I:\ETOS\00-5-3-WA-1
I:\ETOS\00-5-15-WA-1
I:\ETOS\00-5-18-WA-1
I:\ETOS\00-20-1-WA-1
I:\ETOS\00-20-2-WA-1
I:\ETOS\00-20-14-WA-1
I:\ETOS\00-25-06-2-2-WA-1
) do copy %%I C:\users\admin\desktop\age\to

Right now it just copies the contents of each folder without discrimination. I would like it to copy the entire folder (not just folder contents) and only copy those that have been modified within the last seven days.

Possible?

3
  • The answer is 'Yes', it's possible. Myself, I'd use powershell. Please show what you have tried in getting it working and what problems you have observed with your attempts. Commented Apr 19, 2014 at 8:54
  • So I've tried the example below, and it has gotten me closer to my end goal. But i would really like for the file to grab the entire folder, not just the folder contents. Commented Apr 19, 2014 at 14:04
  • I'll elaborate a little more on my issue. I have 9 of these batch files that do exactly that the one above does, except they all have anywhere from 500 to 1500 unique files that they copy from folders not dissimilar from the above. I use 9 different scripts because I need to keep the files that are pulled separated. They all pull from the same I:/ETOS/ directory. Commented Apr 19, 2014 at 14:17

2 Answers 2

1

Test this:

@echo off
for %%a in (
"I:\ETOS\00-5-1-WA-1"
"I:\ETOS\00-5-3-WA-1"
"I:\ETOS\00-5-15-WA-1"
"I:\ETOS\00-5-18-WA-1"
"I:\ETOS\00-20-1-WA-1"
"I:\ETOS\00-20-2-WA-1"
"I:\ETOS\00-20-14-WA-1"
"I:\ETOS\00-25-06-2-2-WA-1"
) do robocopy "%%~a" "C:\users\admin\desktop\age\to\%%~a" /e /maxage:7
Sign up to request clarification or add additional context in comments.

7 Comments

Are the quotations around each file necessary? I have a very long list of folders (so it would take a while to add all the quotes) and currently only have quotes around the names that contain commas or parentheses. Unfortunately I won't be able to check this until Monday while I'm at work.
The code I posted is meant to check for files that have been modified in the last 7 days. It doesn't copy the entire folder if say only one file has been modified, sorry. Your foldernames don't need the quotes as they have no spaces or other characters that cause issues.
Thank you. Is there a way for it to discriminate based on the folder modify date and not the files contained in the folder? The complete end of the line goal here is to have it actually grab .pdf that are contained in folders that have been modified. I'm not concerned with the modify date of the files within, just the folders really.
If you want *.pdf files that have been modified then it could be useful and easier to do that alone.
I wish it were that easy. The drive that I pull these files from is controlled by another party (no one I've even met) and for whatever reason the folders modified date will change, the contents/version of the pdf document will change, but the modified date of the pdf will not. I know it's weird. That's why I want to base it on the folders. I guess I could pull everything from "I:\ETOS\" with the "maxage:7" value and just seperate my pdfs from there. Side question. If i do as stated above, is there a command to delete everything in those dir that isn't a pdf?
|
0

This would work on Powershell V3. For example...

Copy-Item -Path C:\Intel -Recurse -Destination C:\Drivers|Where lastwritetime -GT "04/12/2014 12:00:00 AM"

4 Comments

I'm very new to Powershell, but would like to learn because it seems like it can do more with less. Would you mind breaking that script down for me?
@user3551156 Copy-Item -Path "Source" -Recurse -Destination "Destination" |Where lastwritetime -GT "04/12/2014 12:00:00 AM" Powershell commands are pretty intuitive and self explanatory. You can run man copy -full to get more details about the parameters of the command or you could specify which part is confusing you.
I get it now. I saw you're pats above ie "C:\Intel", but that was just my name not working correctly. I understand whats going on here now. Thanks.
@AyanMullick Wouldn't that script copy all files, regardless of last write time? The Where filter you are applying is only applied to the objects output by the Copy-Item cmdlet, which would be done after the actual copying has been performed. To only copy filtered items, I think you need to do Get-ChildItem (or ls or dir, which are alias for Get-ChildItem), then your Where filter and finally the Copy-Item. So, excluding parameters, it would be like Get-Item {parameters} | Where {filter} | Copy-Item {desinationParameters}.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.