Simple DOS command to ignore data line by line after the last backslash
I am creating a batch file to make multiple directories from a list in a text file however after the directory is sometimes given the filename. Is there an easy way to make it ignore all data after the last line \ on the line?
+1
JAcobv
source
to share
2 answers
I would assume that the DOS package is not the right tool for the job because it does not have built-in string manipulation facilities as it would need.
If you have Perl available, you can do something like this:
#!/usr/bin/perl -w
while (<>) {
s/\\[^\\]*$//; # this removes a the last backslash and anything after it
mkdir $_;
}
+4
Greg Hewgill
source
to share
You can use something like this:
@echo off
set filename="c:\temp\my files\file.txt"
for /f "tokens=*" %i in ("%filename%") do set filename="%~dpi"
echo %filename%
The result will be "c:\temp\my files\"
.
+4
wimh
source
to share