I have a Windows batch file that used to work but since I changed laptop, it fails.
I guess it\'s caused by points (.) in my file path but I haven\'t been able to find a
A bit more explanation why you should always use quotes.
When a path contains parenthesis or ampersands you are in trouble, like in
C:\Program and files (x86)\Tools&Help\bla.txt
When you use it wihout surround it propper with quotes you get a syntax error.
Simplified code
for /f "usebackq" %%j in (%1) do (
SET var=%~dp1
)
The FOR /F
itself works, as long as %1
is surrounded by quotes, but when they are missing it fails.
But the SET var=%~dp1
breaks the code, as it's expanded when the FOR block is parsed to
set var=C:\Program and files (x86)\Tools&Help\bla.txt
The closing parenthesis of x86)
closes the FOR block and the \Tools&Help\bla.txt
are outside of the block and creates a syntax error.
for /f "usebackq" %%j in (%1) do ( SET var=C:\Program and files (x86)\Tools&Help\bla.txt )
In your case, you should modify the code to
for /f "usebackq skip=1 delims== tokens=2" %%j in ("%~1") do (
echo Checking input file from MBP
echo j: %%j
SET "filemb=%~dp1%%j"
)