automatic copy based on file creation date

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
lukbec
Posts: 2
Joined: 25 Jun 2012 03:31

automatic copy based on file creation date

#1 Post by lukbec » 25 Jun 2012 03:39

Hi,
needs help, I have a lot of files in a directory that I wish by creation date to move to the directory which would consist of the year and month the file was created, and then packed catalog, eg 7-zip and deleted catalog.

So I have a file creation date "2012-06-25 14:04" and I would like to script automatically created directory: "201 206" (and moved the files that were created: 2012-06 ....) and so on for the rest of creation date .

Lukas

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: automatic copy based on file creation date

#2 Post by Ed Dyreen » 25 Jun 2012 22:19

'
The timeFormat varies from region to region. :(

Code: Select all

echo.timeStamp: '%date% %time%'

Code: Select all

timeStamp: '26/06/2012 05:51'
Druk op een toets om door te gaan. . .
Look at the for command 'for /?', 'md /?' and 'move /?'

Code: Select all

@echo off &setlocal enableDelayedExpansion

for /f "delims=" %%? in (

   '2^>nul dir /b /a-d "*.*"'

) do    if "%%~?" neq "%~nx0" for /f "tokens=1-2 delims=/" %%a in (

   "%%~t?"

) do (

   echo.md "%%~a %%~b"
   echo.move /y "%%~?" "%%~a %%~b\"
)
pause
exit
Remove the 'echo.' commands if you are happy with the results and,
if you are having timeFormat issues, play around with "tokens=1-2 delims=/" this is were the magic happens. :wink:

lukbec
Posts: 2
Joined: 25 Jun 2012 03:31

Re: automatic copy based on file creation date

#3 Post by lukbec » 26 Jun 2012 08:12

Ed Dyreen wrote:'
The timeFormat varies from region to region. :(

Code: Select all

echo.timeStamp: '%date% %time%'

Code: Select all

timeStamp: '26/06/2012 05:51'
Druk op een toets om door te gaan. . .
Look at the for command 'for /?', 'md /?' and 'move /?'

Code: Select all

@echo off &setlocal enableDelayedExpansion

for /f "delims=" %%? in (

   '2^>nul dir /b /a-d "*.*"'

) do    if "%%~?" neq "%~nx0" for /f "tokens=1-2 delims=/" %%a in (

   "%%~t?"

) do (

   echo.md "%%~a %%~b"
   echo.move /y "%%~?" "%%~a %%~b\"
)
pause
exit
Remove the 'echo.' commands if you are happy with the results and,
if you are having timeFormat issues, play around with "tokens=1-2 delims=/" this is were the magic happens. :wink:


Thank you very much for your help, the script works. Now I think how it works.

Post Reply