PC Review


Reply
Thread Tools Rate Thread

BATCH programming: Getting dirname without trailing backslash

 
 
Ronny
Guest
Posts: n/a
 
      17th May 2010
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\
 
Reply With Quote
 
 
 
 
Twayne
Guest
Posts: n/a
 
      18th May 2010

In news:0d88bf11-d9a4-4657-8468-(E-Mail Removed),
Ronny <(E-Mail Removed)> typed:
> 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`


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a device for batch-programming USB drives? Talal Itani Windows XP Basics 11 26th Jul 2007 03:31 PM
Is there a device for batch-programming USB drives? Talal Itani Windows XP General 11 26th Jul 2007 03:31 PM
Is there a device for batch-programming USB drives? Talal Itani Windows XP Hardware 11 26th Jul 2007 03:31 PM
Trailing blanks in batch file Ragnar Midtskogen Microsoft Windows 2000 CMD Promt 22 18th Mar 2007 09:06 PM
Batch Programming Woes. OS Checker? Tim Snider Microsoft Windows 2000 CMD Promt 12 2nd Sep 2003 05:43 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:23 PM.