?
Solved

Trimming Path info and change file name to lower case

Posted on 2003-03-04
8
Medium Priority
?
238 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
  • 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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 

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 Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

621 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