![]()
[<<]Message[>>] [<<]Author[>>] [<<]Subject [<<]Thread
Number : 5276 Date : 2003-08-11 Author : Garry Deane Subject : Re: Moving files with xxcopy Size(KB) : 1
--- In xxcopy@yahoogroups.com, "Morten Lunde" wrote: > How can I use xxcopy to move all files from one directory > into several subdirs based on files creation date yyyymmdd > withouth having to create the subdirs? I don't think you can do it in one go at the moment. However I think Kan was talking about the possibility of introducing a file archiving/renaming scheme that could use the file's date as part of the name. That may work if it is introduced. The only thing I can think of is to create a loop with a counter and then use this counter to select files created n days ago and copy them to a directory with a date macro offset by -n days. How useful this would be would depend on the sort of date range you need to deal with. Here is a batch file (NT/W2k/XP) which will do that. It is set to stop if there are no files left or after 20 days. @echo off setlocal set src=d:\test\ set dst=f:\test\ set n=0 :loop if not exist %src%* goto :end xxcopy %src%\* %dst%/$yyyymmdd$\ /rcy/do#%n%/fc/tm-%n%/pd0/po0 set /a n+=1 if %n% GEQ 20 goto :end goto loop :end :: delete empty directories xxcopy %dst% /rsy/s/pd0/x* If you've got a diverse scattering of creation dates over a large date range, I'd use a FOR /F loop and a utility like FI http://home.pe.net/~fpw/freeware/ to extract the creation dates in a convenient form then md/copy/del each file individually. A batch like the following (untested) should get you close. for /f "skip=1 tokens=1-3*" %%a in ('fi /tc/-c/a-d %src%') do ( set tc=%%a set fn=%%d call :move ) goto :eof :move set tc=%tc:-=% md %dst%%tc% 2> nul copy "%src%%fn%" %dst%%tc% > nul if not errorlevel 1 del "%src%%fn%" goto :eof Garry
This message if part of XXCOPY's message Archive. The archive contains all the messages posted at Yahoo!Groups: XXCOPY.