Jump to content

Script to copy file and rename with YYMMDD_HHMM


Recommended Posts

Posted

Heres a similar situation in a batch file I use to save some daily log files - hope its of some help

 

 

for /F "tokens=1,2" %%d in ('date /T') do set day=%%d & set date=%%e

set yyyy=%DATE:~6,4%

set mm=%DATE:~3,2%

set dd=%DATE:~0,2%

set dateserial=%yyyy%%mm%%dd%

ren filedel.log %dateserial%_filedel.log

  • Thanks 1
Posted
Heres a similar situation in a batch file I use to save some daily log files - hope its of some help

 

 

for /F "tokens=1,2" %%d in ('date /T') do set day=%%d & set date=%%e

set yyyy=%DATE:~6,4%

set mm=%DATE:~3,2%

set dd=%DATE:~0,2%

set dateserial=%yyyy%%mm%%dd%

ren filedel.log %dateserial%_filedel.log

 

That's brilliant. Ive been searching for ages. How can I add the time as HHMM after the date?

Posted

With a slight modification to the above script you get:

 

@echo off

for /F "tokens=1,2" %%d in ('date /T') do set day=%%d & set date=%%e

set yyyy=%DATE:~6,4%

set mm=%DATE:~3,2%

set dd=%DATE:~0,2%

set dateserial=%yyyy%%mm%%dd%

set hh=%time:~0,2%

set mi=%time:~3,2%

set timeserial=%hh%%mi%

ren filedel.log %dateserial%_%timeserial%.log

  • Thanks 1
Posted

Is there a way to ensure that there is a leading zero in the time part??

 

When I ran the script this morning, at 8.57am, the file output was 20101117_ 857.jpg, is there a way of displaying 20101117_0857.jpg??

 

is quite important because the next time the script runs is 10am. this means that the 10am images appears before the 8.57am image because of the filename.

 

Thanks

Posted

Change the code slightly to be like this:

 

@echo off

for /F "tokens=1,2" %%d in ('date /T') do set day=%%d & set date=%%e

set yyyy=%DATE:~6,4%

set mm=%DATE:~3,2%

set dd=%DATE:~0,2%

set dateserial=%yyyy%%mm%%dd%

set hours=%time: =0%

set hh=%hours:~0,2%

set mi=%time:~3,2%

set timeserial=%hh%%mi%

ren whatever.jpg %dateserial%_%timeserial%.jpg

 

That should do it :)

  • Thanks 1
  • 1 month later...
Posted
When I ran the script this morning, at 8.57am, the file output was 20101117_ 857.jpg, is there a way of displaying 20101117_0857.jpg

If your images are from a digital camera or webcam you could use ExifTool to read the time and date directly from the image itself.

 

FOR %%i IN (*.jpg) DO EXIFTOOL -d "%%Y%%m%%d_%%H%%M%%S.jpg" "-FileName

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...