Answer for:

Renaming JPG Files With a Batch File

Message 4 of 6

View entire thread
0 Votes

When I call the batch from a command prompt, it worked. But executing it from the system, the set did not work within the loop. I changed it to use 2 batch files, #1 executing the loop and #2 doing the work, as follows:
FOR %%V IN (D:\testing\*.jpg) DO renamePix2 %%V

@echo off
SET curfile=%1
SET Yr=%date:~10%
SET Mn=%date:~4,2%
SET Dy=%date:~7,2%
SET Hr=%time:~0,2%
SET Mnt=%time:~3,2%
ECHO Current filename is %curfile%
SET newfile=GR%Yr%%Mn%%Dy%-%Hr%%Mnt%-%curfile:~-8%
ECHO New filename will be %newfile%

IF EXIST %newfile% (
ECHO Cannot rename %1
) ELSE (
ECHO Renaming "%1" to "%newfile%"
RENAME %1 %newfile%