Create Folder Using File Creation Date

April 18, 2011 at 10:07:38
Specs: Windows XP SP3
I have several hundred files in the same folder with various file creation dates. I need a batch file that will create a new folder based on the creation dates of the files in the original folder, then move each file to its corresponding date folder. Example:

File1 created 01/01/2011
File2 created 01/02/2011
File3 created 01/03/2011
File4 created 01/03/2011

After the batch file has run, I should have 3 new folders (01012011, 01022011, and 01032011). File 1 should have been moved to Folder 01012011, File2 should have been moved to Folder 01022011, and File3 and File4 should have been moved to Folder 01032011.

Can anyone help with this.

Thanks,


See More: Create Folder Using File Creation Date

Report •

#1
April 18, 2011 at 16:22:48
@echo off & setLocal EnableDELAYedExpansion
for /f "tokens=*" %%a in ('dir %1/*.* /b') do (
  set T=%%~Ta
  set Month=!T:~0,2!
  set Day=!T:~3,2!
  set Year=!T:~6,4!
  md %1\%Month%%Day%%Year%
  copy %1 %1\%Month%%Day%%Year%
  )

Note: %1 is the value you pass to the BAT when executing like...

c:\>mycopy.bat c:\myfiles

so you can specify what directory you want to do this on.


Report •
Related Solutions


Ask Question