Batch file to move all subdirectories except one

jfunk

Golden Member
Oct 16, 2000
1,208
0
76
Not sure how to do this.

I have an application that produces various files inside folders named by date. It also produces index files named by date in the root folder.

I want to have a scheduled task to run at the end of every month to move all of the folders to a different location, except the current day's items. OS is Win2K3.

Example:

C:\FOLDER contains 20090701.txt, 20090702.txt, 20090703.txt, etc...

C:\FOLDER\LOGS contains subdirectories named: 20090701, 20090702, 20090703, etc...

I want to MOVE all the files in C:\FOLDER and all the subdirectories in C:\FOLDER\LOGS to a different location, but not touch today's files.

Suggestions?

Thanks,

j
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
If the extensions are consistent - just change the extension of what you do not want to move.

Run a xcopy batch file to copy the files and delete the originals by extension.
rRname the unmoved file back to proper extension and you should be all set.
 

Engineer

Elite Member
Oct 9, 1999
39,230
701
126
Are you running this on the last day of the month or the 1st day of the next month? (yes, it can make a difference :p )
 

Engineer

Elite Member
Oct 9, 1999
39,230
701
126
The following will change the name of today's text file, move the others to the folder of your choice, and then rename today's text file back...

You need to download Deltree.exe (to remove the directories by wildcard)...

Click me for Deltree.exe.

You need replace c:\backupfolder with the location that you want to copy this stuff to. Also, you need to substitute the c:\path\ for your location that you store deltree.exe.


c:
cd \FOLDER
ren %date:~10,4%%date:~4,2%%date:~7,2%.txt sample.txt
move 2*.txt c:\backupfolder
ren sample.txt %date:~10,4%%date:~4,2%%date:~7,2%.txt


cd logs
ren %date:~10,4%%date:~4,2%%date:~7,2% sample
xcopy 2*. c:\backupfolder\logs /E
c:\path\deltree /Y 2*.
ren sample %date:~10,4%%date:~4,2%%date:~7,2%

 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
It is frustrating to provide advice/guidance to people then they never show back to follow up.:|
 

Engineer

Elite Member
Oct 9, 1999
39,230
701
126
Originally posted by: Common Courtesy
It is frustrating to provide advice/guidance to people then they never show back to follow up.:|

I just want to know if it works. By helping people out lately, I've dug up old programming that I've used to help myself out (backing up files by date in folders via example of the same batch file above).
 

Engineer

Elite Member
Oct 9, 1999
39,230
701
126
Originally posted by: statik213
install the windows 2003 resource kit then use robocopy, robocopy /? for help:

robocopy srcDir destDir /XF "fileName to exclude" /XD "subdirs to exclude"


--
http://www.microsoft.com/Downl...790cffd&displaylang=en

That sure the hell beats my solution, lol! :p

Edit: How to create it in the form to exclude "today's" file and "today's" folder though without manually typing the entry?

Edit #2: Nevermind, it has maxage and minage options to allow by dates (i.e. over 1 day old, etc).
 

jfunk

Golden Member
Oct 16, 2000
1,208
0
76
Hey all, thanks for the help.

Sorry I was MIA for a while there, had some priority stuff come up and this kind of got pushed aside, then I went on vacation.

I completely forgot about Robocopy! Thanks for the reminder, that will certainly do the trick...I actually have that installed on my workstation and still forgot about it. Doh.