Reputation: 65
x
Not success in rename the file in windows batch script. please kindly advise. appreciate the help
set "source=C:\Users\Processed"
for /f "delims=" %%A in ('findstr /s /m /l /c:"949010" "%source%\*"')
do (
set "fname=%%A"
setlocal enabledelayedexpansion
set "fname=!fname:{=!"
ren %%A "!fname!"
endlocal &
copy /y "%source%\%fname%" "C:\Users\949010" )
Upvotes: 0
Views: 106
Reputation: 65
set "source=C:\Users\Processed"
for /f "delims=" %%A in ('findstr /s /m /l /c:"949010" "%source%\*"') do (
set "fname=%%~nxA"
setlocal enabledelayedexpansion
set "fname=!fname:{=!"
ren "%%A" "!fname!"
copy /y "%%A" "C:\Users\949010"
endlocal
)
Upvotes: 0
Reputation: 67216
You have 5 small errors in your code when I reviewed it! BTW it is a bad idea to modify the original code with no advice of what you did in the question itself...
fname
variable must contain just the name and extension of the file, so ~nx
modifier must be used in %%A
variable.do
clause must be placed in the same line of the for
command.ren
command both names should be enclosed in quotes (not an error in this case).&
sign is used to separate two commands in the same line. It should be a command after the &
.for
loop must be enclosed in exclamation-marks.endlocal
command must be placed after the last variable with exclamation-marks.I also modified the justification of the code in the standard way.
This is the corrected code:
set "source=C:\Users\Processed"
for /f "delims=" %%A in ('findstr /s /m /l /c:"949010" "%source%\*"') do (
set "fname=%%~nxA"
setlocal enabledelayedexpansion
set "fname=!fname:{=!"
ren "%%A" "!fname!"
copy /y "%source%\!fname!" "C:\Users\949010"
endlocal
)
Upvotes: 2