Solved Specify Full Path in Batch script FOR statement

October 19, 2012 at 12:12:58
Specs: Windows 7
Hopefully this is a simple issue with quotes that I'm just mixing up. I have a FOR loop where if I type in just the files to search it works, but if I specify a full path it doesn't work. I am using something similar with delims and everything works as expected so not sure what the problem is here.

This works no problem if I manually change to the needed directory first:

setlocal enabledelayedexpansion
for %%b in ("_*.mp3") do (
set "fn=%%b"
ren "%%b" "!fn:~1!"
)
endlocal

However, I don't want to change directories first and instead want to specify the path in this statement. The following does not work, giving an error that the syntax is incorrect. If I change the to single quotes around the path or add single quotes around the path, that also doesn't work. Please advise what I'm doing wrong.

setlocal enabledelayedexpansion
for %%b in ("C:\Folder\_*.mp3") do (
set "fn=%%b"
ren "%%b" "!fn:~1!"
)
endlocal


See More: Specify Full Path in Batch script FOR statement

Report •


#1
October 19, 2012 at 12:22:30
✔ Best Answer
Replace:
set "fn=%%b"
With:
set "fn=%%~NXb"

How To Ask Questions The Smart Way


Report •

#2
October 19, 2012 at 12:26:11
Perfect! thank you very much for the prompt response.

Report •

Related Solutions


Ask Question