BATCH programming: Getting dirname without trailing backslash

R

Ronny

Suppose I have a variable FILE which contains the full path to a file.
To store the name of the directory where this file is stored, I use in
my batch file the following assignment:

for %%F in ("%FILE%") do set DIR=%%~dpF

This works, but %DIR% contains the directory name with a trailing
backslash
added. Is there an easy way to get the directory name WITHOUT the
backslash?

For instance, if FILE is \\share\c:\foo\bar\baz.txt, I would like DIR
to contain
\\share\c:\foo\bar and not \\share\c:\foo\bar\
 
T

Twayne

In
Ronny said:
Suppose I have a variable FILE which contains the full path
to a file. To store the name of the directory where this
file is stored, I use in my batch file the following
assignment:

for %%F in ("%FILE%") do set DIR=%%~dpF

This works, but %DIR% contains the directory name with a
trailing backslash
added. Is there an easy way to get the directory name
WITHOUT the backslash?

For instance, if FILE is \\share\c:\foo\bar\baz.txt, I
would like DIR to contain
\\share\c:\foo\bar and not \\share\c:\foo\bar\

Use Find to see if the last character is a back slash (or a forward flash,
for that matter). If it's there, remove it by truncating.

alt.msdos.batch.net has some real experts there. They're great for
these kind of questions but be polite and professional.

HTH,

Twayne`
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top