You are not logged in.
Pages: 1
Hi, My name is Marcus.
I've been doing a lot of batch scripting here lately. And I've came up with a script that will convert a path to a directory that has long names to their short 8 character names. I'd figure this script would be fairly useful for batch programmers that are doing heavy searching for files in their own batch scripts. But I would like to know, especially on this kind of forum, of what you guys think of my batch script.
Hopefully this script will help many, but feel free to post your comments about the script. Anything you think needs to be changed or modified, or what can be done faster I would be more than glad to here about. Rate my batch script.
Thanks!
Offline
Interesting stuff, my first thought is what if the creation of short names has been disabled with
"FSUTIL behavior set disable8dot3 1"
You can check the current setting of this with "FSUTIL behavior query disable8dot3 1"
Offline
I tried out FSUTIL and it really didn't do much as far as getting information from directories.
My main focus of the script was to get the short name of the directory name if it exists so you could properely access a file or an application without using quotes.
Currently I'm writing a script called TRONRez, a batch application that helps you setup the tools you need to edit the game TRON 2.0, and I found out that for some reason I couldn't quote a path to an application file from the use of the for /F "options" %%parameter in ('command'). This is what lead to me to actually writing this script.
I could of sworn I did it before, but for some reason I get invalid command errors if I do quote the full path to that particular application file.
This way, when you try to access a file, you'll know it will always be under that specified path.
Offline
To call a command using FOR via a long pathname you need the usebackq option
FOR /F "usebackq" %%G IN (`c:\program files\some command.exe`) DO ECHO %%G
Offline
Using the backquote is not entirely necessary, unless some how LNFs would work in Windows 2000 for some strange reason, but probably not so. Plus if you wanted to use LNFs for the path to the command in the FOR-Files loop, you would have to quote the path. But the thing is, you can only use one set of quotes within the single or backquoted barrier, even if you escape the quotes by using the carrot character. So if you were to use a command that had to reference another path that also has LNFs, one of the paths would have to use short names, or both to where you wouldn't even have to use quotes.
Offline
OK sorry the right syntax to get long filenames to work is this
FOR /F "usebackq" %%G IN (`"c:\program files\some command.exe"`) DO ECHO %%G
the back quotes ` tell FOR that this is the file/command we want to run
the normal double quotes " delimit the long filename w/ spaces
so for example you can add parameters like so
FOR /F "usebackq" %%G IN (`"c:\program files\some command.exe" /?`) DO ECHO %%G
That said I wouldnt be surprised if there are exceptions where this fails to work, I tested this in XP sp2
Offline
My main system is also running XP sp2, but I don't see where using backquotes actually helps. Because if you leave out backquotes like this:
FOR /F %%g in ('"C:\Program Files\command.exe"') do echo.%%g
The application in in the Program Files folder will still execute. I'm confused about the benefits of backquotes.
What you cannot do, regardless of what type of single quotes you use for the barrier, you cannot use two sets of double quotes.
Valid
FOR /F %%g in ('"C:\Program Files\command.exe" -parameter value') do echo.%%g
and
FOR /F %%g in ('^"C:\Program Files\command.exe^" -parameter value') do echo.%%g
Invalid
FOR /F %%g in ('"C:\Program Files\command.exe" -parameter "value"') do echo.%%g
and
FOR /F %%g in ('^"C:\Program Files\command.exe^" -parameter ^"value^"') do echo.%%g
and even
FOR /F %%g in ('"C:\Program Files\command.exe" -parameter ^"value^"') do echo.%%g
Offline
Yes I see what you mean now - usebackq doesnt make any difference, for a file-set usebackq would allow "long file 1" "long file 2"... but for executing a command it doesnt help.
What i would suggest is a temporary file for the command
set _prog="C:\Program Files\command.exe" -parameter "value"
echo %_prog%>%temp%\mycommand.cmd
FOR /F %%g in ('%temp%\mycommand.cmd') do echo.%%g
DEL %temp%\mycommand.cmd
unless anyone else has a better idea?
Offline
Yeah that works really good actually, I was not familiar with cmd files.
Less code, and it only needs to be done when you're in need of using the output of a file in FOR /F loop.
Do cmd files work in Win9x as well?
Offline
The distinction between BAT and CMD files is simply that win95/98 wont attempt run a CMD, which can be a good thing if it's full of NT/XP specific syntax. I havent used Win9x since about 1996 so I'm in the habit of writing everything as a cmd
Offline
Hey Simon, check this out:
for %%g in ("C:\Program Files") do echo. %%~fsg
echo. C:\PROGRA~1
Durh! LoL. Oh well live and learn.
Offline
nice!
cmd, vbs, ps, bash
autoit, python, swift
Offline
Pages: 1