user1143479
user1143479

Reputation: 1

dos batch file for move of files

Is there a way to move files in a directory (we have 1.7 million) to folders based upon a date? WOuld like to move all files created between 1-1-2010 and 2-1-2010 to a specific folder

Upvotes: 0

Views: 1169

Answers (2)

Malignus
Malignus

Reputation: 31

You can use the Robocopy feature. It comes as default in Windows Vista and Windows 7 and you can download it in Windows XP in the microsoft website.

If your Windows is 64 bit it even move files that have a path longer than 256 characters, unlike the CTRL+C, CTRL+V on Windows Explorer (I can't understand why). To see the program help you can write the following in the DOS Prompt (example, usually you can't write to the root):

robocopy /? > c:\robocopyhelp.txt

Use the switches "/MINAGE" for setting the minimum age of the file to be copied/moved and "/MAXAGE" for setting the maximum age.

I've never moved files before and never tried to filter them by age, but I think the syntax should be (from drive F to G, for example, and only 2011 files):

robocopy F:\ G:\ /MOVE /MAXAGE:20110101 /MINAGE:20111231

Plus other parameters described on the "robocopy /?". Usually I add "/R:0 /W:0", for it not try to access systems files (can help if you run the batch file with administrator privileges) 1 million times with a wait time of 2 seconds for each system file it can't copy/move (2 million seconds or 23 days for just pagefile.sys and hiberfil.sys). And the "/A-:H" switch to un-hide the hidden files.

Keep in mind also the existence of NTFS Junctions (infinite loop in the C:\users directory) and encrypted directories and use the according switches.

Upvotes: 2

Joey
Joey

Reputation: 354794

This won't be very nice, but you could use forfiles twice. Once to move all files with a date greater than 2010-01-01 to the folder and a second time to move all files with a date greater than 2010-??-?? (can't parse your date format reliably) back to the original folder.

Not pretty, definitely.

Upvotes: 0

Related Questions