|
Answer» Hello,
First off, I'd just like to thank anyone who reads/answers this thread. I have no experience in this area whatsoever so I would really appreciate any help I can get.
For work, I have been tasked with archiving any files older than January 1st, 2012. I'd like to move older files from N:\New Filing System (.doc, .xls, .mp4, etc.) to E:\Archived. The perfect solution would copy the files to E: drive and delete them from the N: drive, but I would be happy with it at least copying them over. Then I would CONDUCT a search and just delete the old files.
Actually, I FOUND a code like this:
Code: [Select]for %A in (*.*) do @xcopy /D:12-8-08 /L "%~fA" "%~fA" >NUL 2>NUL &&echo.DEL "%~A" I was hoping I could use that to do the second part of my plan (deleting files). Would this code go through all SUBDIRECTORIES or only the current folder?
Edit: When I search files older than Jan 1 2012, I find around 24,000 files.
I have read dozens of threads that deal with similar issues but either the codes don't work or I just don't understand how to alter them to fit my needs. I read about Robocopy and Forfiles but neither of the kits are allowed to be installed on my computer (says our IT group) so I am stuck with playing around with the basics. I've also tried the move command but I'm really struggling with the syntax of that one and batch files are super confusing.
I hope my question was EXPLAINED clearly. Again, I know this probably has appeared in the forum before and I have come across a few topics, but none of the solutions (although GREAT solutions) worked for me. I am a novice beyond a novice in this area!!
Thanks again and I apologize for the inconvenience this question may cause you and for most likely repeating a thread. I really appreciate any help!Try this:
Code: [Select]@echo off for /r %%A in (*.*) do if %%:~tA LEQ 2012 echo xcopy "%%~A" E:\Archived\%%A >>log.txt notepad log.txt
It should write a list of all the files it would move, in the form of the command that would move them. (I don't know if this will take the subfolders over, or just the files)Thanks for your reply! For the first time in a long time, it actually worked to produce something. Unfortunately it didn't really produce the results I wanted. Sorry about this pickiness, but I needed something that could move all 24,000 files over in one go. Even if it is just a copy and paste job, it would help so much. I'm really sorry that it didn't work but you have no idea how much I appreciate your help! Thanks for taking the time to read and reply.
Edit: Is there a way to do a list of things that should be excluded? So do xcopy and then build a list from there, make it an exclude list, and then repeat xcopy so everything moves except the things on the list (theoretically would be things after Jan 1, 2012)?This should give you a list of all the NEWER files from 1/1/2012 (it will not copy them with the /L switch) and you can then create a batch file to use that information in xcopy.log and MOVE all those files to a new folder tree, then change the top level folder names of the two trees to suit you. The new tree will have post 2011 files and the old tree will have files before 1/1/2012
Code: [Select]xcopy /s/h/e/k/f/c /d:12-31-2011 /L "N:\New Filing System\*.*" "E:\Archived\" >"%userprofile%\desktop\xcopy.log" Actually, your comment about excluding files is a good one - you could use the xcopy.log that is created to exclude all those post 2011 files in an xcopy operation, then another batch file can use the copied tree to remove all those filenames from the original tree.
This second command on the xcopy.log file will modify the information so that it contains only the drive:\path\filenames of the newer files and you can use that as an exclude file in an xcopy command.
It uses a helper batch file called repl.bat: from - http://www.dostips.com/forum/viewtopic.php?f=3&t=3855
Code: [Select]type "%userprofile%\desktop\xcopy.log"|repl "(.*) ->.*" "$1" >"%userprofile%\desktop\xcopy2.log"Absolutely perfect!!! Thank you so much for your reply, foxidrive. Great information and great help. It completed what I wanted! Again, thank you very much for your time and help. Super appreciate it. And thanks to everyone who read this thread, too!
|