How to code a batch file to transfer subfolders inside a main folder which are created X days back.i used forfiles and achieved a lot of it , but not getting the folder structure in proper. Kindly suggest.
First, post your existing code (if you intend to modify/use it). Might be xcopy or robocopy can do what you want without "coding".
Thanks foy your reply. I am using windows XP , SP2. I came up with the following
code> As you can see , Source Folder is RMFOLDER & destination is NEW. I want
to keep files or Sub-folders which are maximum 3 days old.
@echo off
CD C:\RMFOLDER
FORFILES -pC:\RMFOLDER -m*.* -d-3 -C"CMD /C XCOPY c:\RMFOLDER\@FILE C:\NEW\ /S"
//forfiles -p"C:\RMFOLDER" -d -3 -c"CMD /c XCOPY "C:\RMFOLDER" "C:\NEW""forfiles -p"C:\RMFOLDER" -d-3 -c"CMD /C del \"@PATH\@FILE\""
Pause
I think with forfiles all you need is this one-liner: @FORFILES -pC:\RMFOLDER -d+3 -C"CMD /C move @PATH\@FILE C:\NEW"
Your date criteria being maximum 3 days old, then I think you'd want the "+" and not the "-" for the -d option.
Since you spec'd subfolders as well as files, this will move subfolders (without having to use xcopy /s), but all files in those subfolders will be moved, not just the ones less than 3 days old. I didn't use the -s option for that reason, but I might have misinterpreted what your intentions. If you do want to move (or copy) the directory structure, but only those files newer than 3 days, the code could be modified to do so using the -s option.
FORFILES /D+3 would be anything modified after 3 days into the future. No, I'm not sure why anyone would want to check for that.
It's probably the forfiles version I downloaded. It's, like, ancient (version 1.1, by emmanual boersma?) It works for this, but maybe not the way the mainstream version does it. (I wondered about that myself, why anyone would want to specify files 3 days newer than the current (system) date, when what it really needs to determine is whether to include or exclude files x number of days older than current date. I figured forfiles would be in the resource-tool-kit I downloaded (mainly to obtain robocopy for my xp) but it wasn't.
Here's what the help-screen showed:
-d[+|-][DDMMYY|DD] Select files with date >= or <=DDMMYY (UTC)
or files having date >= or <= (current date - DD days)
Yeh, it's old, but I downloaded another one that's about 5 times bigger, but it has the same author, version and date (4/98) so i don't know what the difference is, but they both seem to work ok. Hoping I didn't download a virus though.
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |