Click here for important information about

Solved create batch file to transfer subfolders

June 6, 2013 at 10:40:26
Specs: Windows 7
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.

See More: create batch file to transfer subfolders

June 6, 2013 at 18:05:40
First, post your existing code (if you intend to modify/use it). Might be xcopy or robocopy can do what you want without "coding".

Report •

June 10, 2013 at 04:10:02

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



//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\""


Report •

June 10, 2013 at 20:28:02
✔ Best Answer
I think with forfiles all you need is this one-liner:


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.

Report •

Related Solutions

June 11, 2013 at 09:09:24
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.

How To Ask Questions The Smart Way

Report •

June 11, 2013 at 13:37:05
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)

Report •

June 11, 2013 at 13:41:44
To be fair, it sounds like you got a sane version.

How To Ask Questions The Smart Way

Report •

June 11, 2013 at 14:01:17
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.

Report •

Ask Question