Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Computing > Alt Msdos Batch Nt > Finding a file ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 3303 of 3395
Post > Topic >>

Finding a file extension in a variable

by Calvin <nospam@[EMAIL PROTECTED] > Jun 19, 2008 at 01:12 PM

Hi All,

I suspect the answer to this would be (fairly) simple for an experienced 
batch file writer - but because I am using the 'for' command (the syntax 
of said command I'm sure was originally written in Swahili !) I'm having 
a few problems :-(

I have a variable (%VariName%) which contains a fully qualified 
path.filename.ext string.  eg: D:\Path1\Path2\File Name.ext

I want to recover the JUST the extension into a new variable (%FileExt%).

Currently I'm using:

for /f "tokens=2 delims=." %%a in ('echo %VariName%') do set FileExt=%%a

  (probably wrapped but actually 1 line :-)  )


This works, but will of course fails if there are any '.' characters 
within the path or filename areas of the variable (because of the 
'tokens=2')

I note that the syntax of the 'for' command has been expanded with new 
%~x parameters which supposedly allow extraction of specific parts of 
fully qualified filename - but I'm at a total loss trying to decipher 
how to do so :-(

TSCMD seems to be reasonably silent on this issue - the couple of 
references I found to it really didn't help explain the syntax or use. 
Could somebody be so kind as to enlighten me - or suggest an alternate 
9simpler) approach to the problem.

Calvin.
 




 3 Posts in Topic:
Finding a file extension in a variable
Calvin <nospam@[EMAIL   2008-06-19 13:12:26 
Re: Finding a file extension in a variable
"billious" <  2008-06-19 11:54:43 
Re: Finding a file extension in a variable
Calvin <nospam@[EMAIL   2008-06-21 00:50:14 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Aug 29 22:38:02 CDT 2008.