I have been doing a lot of reading and can't quite find an exact answer to my question. I have seen similar posts but not exactly this.
I have a program that generates names of files like:
d:\a and b\1 and 2.mkv
d:\a & b\1 & 2.mkv
d:\aandb\1and2.mkv
The point being is I can't control the output of the folder name or file name. I have a post processing script that takes that fully qualified file and runs commands on it. I can't seem to correctly call my post processing script that will correctly handle the fully qualified filename when the fully qualified filename could be any of the examples listed. Because I can't control the folder or file name, escaping the ampersand won't help. I have tried about ever combination of variables while using !variable! or %variable% and I can't seem to come up with a way that will handle any combination of folder or filename with ampersands or spaces in them.
How do I correctly pass the fully qualified filename to another batch file so that it correctly interprets the fully qualified filename whether it has spaces oe ampersands or doesn't have them?
Just one of the examples:
test.cmd "A & B\1 & 2.mkv"
where test.cmd
@echo off
@setlocal EnableDelayedExpansion
@set TARGETDRIVE=%~d1
@set TARGETPATH=%~p1
@set TARGETNAME=%~n1
@set TARGETEXTENSION=%~x1
@echo TARGETDRIVE=!TARGETDRIVE!
@echo TARGETPATH=!TARGETPATH!
@echo TARGETNAME=!TARGATNAME!
@echo TARGETEXTENSION=!TARGETEXTENSION!
The output:
'B' is not recognized as an internal or external command,
operable program or batch file.
'2' is not recognized as an internal or external command,
operable program or batch file.
TARGETDRIVE=z:
TARGETPATH=\temp2\A
TARGETNAME=
TARGETEXTENSION=.mkv