Link to home
Start Free TrialLog in
Avatar of dalexan12456
dalexan12456Flag for United States of America

asked on

Move files that fall within a date range

Help!  Here's my situation.  On my Windows Server 2003 box, I have a folder that has so many files that I can now longer browse to it.  I need to move files that were created between July 1, 2005 - June 30, 2006 to a different location.  I have to use DOS commands to accomplish this but my "DOS for Dummies" reference book (which had to be dusted off) doesn't provide me any clue on how to accomplish this.

THANKS!!
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dalexan12456

ASKER

sirbounty -

Let me see if I can find someone on the server team to download the server tool kit; I just tried the command from a command line in hopes that it might already been installed to no avail.  

If I wanted to do different date ranges, how would I do that?

Thanks!
I just placed your two date values in excel and subtracting them each from today...
sirbounty -

When I tested this, I discovered that none of the expected files were moved; instead, all of the other files were moved!  I did some research and discovered that robocopy copies everything unless you add a switch to exclude files - so it didn't move anything from July 1, 2005 - June 30, 2006.  I tried again, but used the following instead -

robocopy c:\sourcefolder d:\targetfolder *.* /move /minage:20050630 /maxage:20060701

where minage is June 30, 2005 and maxage is July 1, 2006.  
Thanks for cluing me into robocopy!


Ah - I've always used the calcuations for my purposes in this scenario.
Glad you got it working - robocopy is indeed a great admin tool...don't part with it! :^)
Thanx
Avatar of Meldrachaun
Meldrachaun

Here's a batch file that will do the trick - run in the directory you want to move the files from, and replace d:\mydir to the place you want to copy the files.  Copy and Paste the bat file, don't retype - some of the vars are case sensitive.

@echo off

if exist filelist1.txt del filelist1.txt
if exist filelist2.txt del filelist2.txt
if exist DoMove.bat del DoMove.bat

for %%I in (*.*) do @echo %%~tnxI >>filelist1.txt

findstr /R ^0[7-9]/[0-9][0-9]/2005 filelist1.txt >>filelist2.txt
findstr /R ^1[0-2]/[0-9][0-9]/2005 filelist1.txt >>filelist2.txt
findstr /R ^0[1-6]/[0-9][0-9]/2006 filelist1.txt >>filelist2.txt
for /F "tokens=4*" %%I in (filelist2.txt) do echo move /y "%%I %%J" d:\mydir\ >>DoMove.bat
call DoMove.bat
del filelist1.txt
del filelist2.txt
del DoMove.bat
Here is something even easier!
FORFILES -p "D:\Backup\" -s -m *.bak -d -8 -c "CMD /C del @path"

-d -8 ---files older than 8 days
*.bak --- file types / extension