![]() |
|
![]() | ||
|
Subject:
Moving subfolders from one folder to another
Category: Computers > Software Asked by: krisl-ga List Price: $15.00 |
Posted:
31 Aug 2004 17:31 PDT
Expires: 11 Sep 2004 06:45 PDT Question ID: 395359 |
My users create folders inside of c:\CreateHere. These folders contain data, and can also contain subfolders. I would like a batch file that I can run nightly. I would like this batch file to move all folders over 7 days old into several archive folders: C:\ArchiveHere\A-D (all top-level folders inside of c:\CreateHere beginning with A,B,C, or D, will be moved here) C:\ArchiveHere\E-H (all top-level folders inside of c:\CreateHere beginning with E,F,G, or H, will be moved here) et cetera for the rest of the alphabet. I have robocopy and realize that I can use the /MINage:7 with /MOVE parameters to move files that are older than 7 days... however, I'm unable to come up with the correct parameters to move an entire folder (and all contained sub-folders) into the archive folder. robocopy doesn't seem to like wildcards as the source. I've even tried "for/in/do" batch file commands. If I do a "dir *." from a command line, it will show me all folders. However, if I do a "for %%f in (*.) do echo %%f", I get no results. Apparently the wildcard inside of that command doesn't display folders.. only files. An acceptable answer would be an example of something that works, whether it be a batch file using robocopy, a .vbs, or even a little perl script. |
![]() | ||
|
There is no answer at this time. |
![]() | ||
|
Subject:
Re: Moving subfolders from one folder to another
From: crythias-ga on 31 Aug 2004 20:50 PDT |
I was working on it, and it's tough, to be sure. Which OS to write for? :) here's some things to look at, in the mean time: Get today's date: echo. | date | find "Current" Directory list of directories, 4 digit years, sorted by date dir /4 /od /ad | find "<DIR>" I was going to do awk processing, but awk doesn't handle a "date" parameter very well. I have a "-7 days" code, but "before" comparisons aren't easy. :) if I had an option to archive the previous month, instead of seven days, it'd be a snap :). |
Subject:
Re: Moving subfolders from one folder to another
From: krisl-ga on 31 Aug 2004 21:54 PDT |
Sorry, should have specified - Windows server 2003. Yeah, if you google for: batch file +if "days old" You find a few batch files that delete files that are x days old.. but they are ~200 lines long (Well, one that works with leap years and such is). Pretty ridiculous. Still doesn't solve the problem of moving an entire directory. If the wildcards in the for/in/do command returned folders instead of just files, I could probably "mkdir c:\ArchiveDir\A-D\%%f | robocopy ..(etc)". Now I'm just rambling. :) Thanks for the comment. |
Subject:
Re: Moving subfolders from one folder to another
From: crythias-ga on 31 Aug 2004 22:20 PDT |
considering programs like http://winadmin.sourceforge.net/warmzip.html, I have to ask why not use this or backup software in "prune/archive" mode to simply do the job for you? Actually, that is the solution you need! Schedule to prune the info, then schedule to restore to alternate location, keeping the tree (if you must)... I think robocopy might be able to do this, too. This or xcopy. Frankly, I would rather just prune every day 7 days old into a new file or folders. But, still... this might be done in a scripting language that can handle date differences properly. |
Subject:
Re: Moving subfolders from one folder to another
From: krisl-ga on 01 Sep 2004 13:19 PDT |
With that app, I'm *almost* there. The only problem with that app.. is that it won't work with wildcards. I can't tell it to move all directories that start with A to one location, B to another, etc. |
Subject:
Re: Moving subfolders from one folder to another
From: krisl-ga on 01 Sep 2004 14:40 PDT |
I think I'm 90% of the way there. I could run a batch file that would do this: ROBOCOPY c:\CreateHere\ c:\TempDest\ /move /minage:7 That will move everything older than 7 days to a temp dir. Then, cd \TempDest for /D %f in (A*.*) do mkdir "c:\DestDir\A-D\%f" | robocopy /e "%f" "c:\DestDir\A-D\%f" | rmdir /S /Q "%f" the /D option on the 'for' command only returns directory names. That will create the directory inside of a-d with the same name as the one in \TempDest, move the files there, then delete from TempDest. I would run that for each letter of the alphabet. My only problem is... I really only care about the date on the folder inside of CreateHere itself, I don't care about the date on the files contained within. Does the folder always have a date of the most recently updated file within it.. ? I don't want the robocopy command to exclude 1 file in the folder because it's newer... |
Subject:
Re: Moving subfolders from one folder to another
From: crythias-ga on 02 Sep 2004 06:22 PDT |
You could use "move" instead of robocopy. :) You just need to filter your folder list. I think there's something that can be done if one serializes the dates and can subtract the difference. I'm working on that in awk, but if you find it first, that's ok :). |
Subject:
Re: Moving subfolders from one folder to another
From: crythias-ga on 11 Sep 2004 01:40 PDT |
Also, maybe check out http://answers.google.com/answers/threadview?id=399628 You can get a nice (free... a very liberal license: http://www.activestate.com/Products/ActivePython/license_agreement.plex) version of Python from http://www.activestate.com/Products/ActivePython/ Quick download link: http://www.activestate.com/Products/Download/Download.plex?id=ActivePython |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |