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
automatic copy based on file creation date
Moderator: DosItHelp
Re: automatic copy based on file creation date
'
The timeFormat varies from region to region.
Look at the for command 'for /?', 'md /?' and 'move /?'
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.
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. . .
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
if you are having timeFormat issues, play around with "tokens=1-2 delims=/" this is were the magic happens.

Re: automatic copy based on file creation date
Ed Dyreen wrote:'
The timeFormat varies from region to region.![]()
Code: Select all
echo.timeStamp: '%date% %time%'
Look at the for command 'for /?', 'md /?' and 'move /?'Code: Select all
timeStamp: '26/06/2012 05:51'
Druk op een toets om door te gaan. . .Remove the 'echo.' commands if you are happy with the results and,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
if you are having timeFormat issues, play around with "tokens=1-2 delims=/" this is were the magic happens.
Thank you very much for your help, the script works. Now I think how it works.