Using batch commands how do I get the folder path/directory from a string?
For example, if I have the string “C:\user\blah\abc.txt” how do I split the string so I can just get the folder part, ie, “C:\user\blah\”?
If pass the string “C:\user\blah\abc.txt” in the command line of a batch file, how do I split that string into just the folder part?
REM // Grab "C:\user\blah\abc.txt" from the command line
SET path="%*"
REM // The following doesn't successfully capture the "C:\user\blah\" part
SET justFolder=%path:~dp1%
the ~dp option only works with the batch parameters (%1 %2 …) or with FOR substitution parameters (%%a %%b …). Read
HELP CALL.So, to achieve what you want, try the following code
As an aside note, my personal preference is not to add ” around user entered filenames. I would code the previous code simply as