I am a newbie, trying to write a .cmd file with the following logic
- Look for a file in C:\BatchTest\test\Journal\ folder
- if file name matches 'journalimport_ or JOURNALIMPORT_' then go into for loop
- Replace the filename with proper case 'JournalImport' and echo the updated file name
- After that, I am moving the file to different folder
Here is code:
SETLOCAL EnableDelayedExpansion
set "Dir1=C:\BatchTest\test\Journal\"
set "GLM=JournalImport_"
for /f "tokens=1-9" %%a in ('dir /Q /a-d %Dir1%"*.zip"^|find "%GLM%" /i') do (
set gl_standard_file_name=%%f:journalimport=JournalImport!
ECHO %gl_standard_file_name%
move %Dir1%%%f %Dir1%output\%gl_standard_file_name%
)
pause
Problem: This code works when I run the cmd file from command prompt as shown below
C:\BatchTest\test\bin>(
set gl_standard_file_name=JournalImport_20220915.zip:journalimport=JournalImport!
ECHO "JournalImport_20220910112013.zip"
)
"JournalImport_20220915.zip"
But when I double click the cmd file, the string replace is not working and gl_standard_file_name is coming empty as shown below.
C:\BatchTest\test\bin>(
set gl_standard_file_name=JournalImport_20220915.zip:journalimport=JournalImport!
ECHO
)
ECHO is on.
Please suggest!!