?
Solved

Trimming Path info and change file name to lower case

Posted on 2003-03-04
8
Medium Priority
?
237 Views
Last Modified: 2008-02-01
Hi,

Is there any way I can trim the path info which I am getting along with %1 parameter ( eg:c:\windows\FILE.TXT ==> FILE.TXT and also I want to change the FILE.TXT to lower case  file.txt in a bat file ?

Thanks
0
Comment
Question by:itmenon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 10

Expert Comment

by:pbarrette
ID: 8066453
Hi itmenon,

What operating system are you using?

pb
0
 

Author Comment

by:itmenon
ID: 8067151
win98 and win2K
0
 
LVL 10

Accepted Solution

by:
pbarrette earned 60 total points
ID: 8067607
Hi itmenon,

For Win2K, you can use "%~nx1" instead of "%1" to return the filename minus path info.

With Win9x, it becomes more convoluted. The following batchfile will strip off the path info from %1, provided that the file represented by %1 actually exists.

:: -----PATHS.BAT------
@ECHO OFF
CD > C:\TEMP\CURPATH.TXT
CD %1\..
DIR /B %1 > C:\TEMP\FILEPATH.TXT

ECHO @PROMPT SET CURPATH=>C:\TEMP\TEMP1.BAT
TYPE C:\TEMP\CURPATH.TXT >> C:\TEMP\TEMP1.BAT
ECHO @PROMPT $H >> C:\TEMP\TEMP1.BAT
CMD /C C:\TEMP\TEMP1.BAT >> C:\TEMP\TEMP2.BAT 2>NUL
CALL C:\TEMP\TEMP2.BAT 2>NUL

ECHO @PROMPT SET FILEPATH=>C:\TEMP\TEMP1.BAT
TYPE C:\TEMP\FILEPATH.TXT >> C:\TEMP\TEMP1.BAT
ECHO @PROMPT $H >> C:\TEMP\TEMP1.BAT
CMD /C C:\TEMP\TEMP1.BAT >> C:\TEMP\TEMP2.BAT 2>NUL
CALL C:\TEMP\TEMP2.BAT 2>NUL

CD %CURPATH%

DEL C:\TEMP\CURPATH.TXT
DEL C:\TEMP\FILEPATH.TXT
DEL C:\TEMP\TEMP1.BAT
DEL C:\TEMP\TEMP2.BAT

ECHO FILEPATH = %FILEPATH%
:: -----PATHS.BAT------

If the file does not exist, then it will not set the variable correctly.

Also, if the file is associated with a program in Win98, then Win98 will open, or attempt to open, the file.

If you must do this in Win98, then you are better off using a utility like XSET:
http://xset.tripod.com/

Or using the Win2K syntax in combination with Win95CMD:
http://www.neuro.gatech.edu/users/cwilson/cygutils/consize/Win95Cmd.exe

Hope this helps,
pb
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

Author Comment

by:itmenon
ID: 8072960
Thanks pb.By any chance you know the %1 giving me DOS name ( with "~" sign) ,how can I get the long file name when I am attaching this bat file as an action for a particular file type ?
0
 
LVL 10

Expert Comment

by:pbarrette
ID: 8084005
Hi itmenon,

In which OS are you having this problem?
pb
0
 

Author Comment

by:itmenon
ID: 8089388
win98
0
 
LVL 10

Expert Comment

by:pbarrette
ID: 8090627
Hi itmenon,

This should already be returning the long filename. Keep in mind that if you are using this before Windows loads, like in AUTOEXEC.BAT, then long filenames can't be used.

If you want to get the shortfilename of a long filename, you can use:
TRUENAME %FILEPATH%

But it may not report the correct shortname.

pb
0
 

Author Comment

by:itmenon
ID: 8093873
Hi Pb

Thanks for the reply.Actually I have posted this as a new question with more details of my problem.Please have a look
 http://www.experts-exchange.com/Operating_Systems/Win98/Q_20541528.html
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question