English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

For all you command-line hackers. I need to be able to convert a long file name to a short one at command line.

Example:

D:\My User Name\My Documents\IM Archives\archive1.txt

to

D:\MyUser~1\MyDocu~1\IMArch~1\archiv~1.txt

I tried using rundll32 to call windows api but was unsuccessful.

Can anyone help?

2007-03-26 00:45:08 · 2 answers · asked by Anonymous in Computers & Internet Software

Here are a few details in response to Kevins answer:

* I need to do this only for one file.
* I need this for use in config file of a software that does not support long names :-(
* dir /x doesnt work for me. I know the location of the file i am trying to find a short name for. I simply want to convert it to a short name for use with a config file which i am constructing on the fly before invoking the software.

thanks in advance..

2007-03-28 12:25:48 · update #1

2 answers

The "/x" switch on 'dir' will give you the shortname of files and folders.

Examples,

1) Listing the short name for a file with a long name,

C:\Documents and Settings\All Users\Desktop>dir /x
Directory of C:\Documents and Settings\All Users\Desktop
03/27/2007 07:31p 168 LONGNA~1.TXT longname test.txt

2) Listing the short names of directories with long names

C:\Documents and Settings>dir /x
Directory of C:\Documents and Settings
03/12/2007 08:29a

ADMINI~1 Administrator
03/15/2007 09:27a ALLUSE~1 All Users

Doing multiple subdirectories and the filename from one commandline is going to be a bit tough, but I'll see what I can come up with.

Questions to help with the answer,
Do you always know where the archive1.txt file will be?
Is that in a static location, or do you have to locate the file(s) each time?
Most importantly, why do you need the short names?

===========================
Updated to answer details:

If you already know the exact location of the file and the name of the file, then you should be able to use 'dir /x' at each directory to get the appropriate short name and on the file to get its short name ... unless I'm missing something from your details?

For instance, if I have a file called "long filename.txt" on the administrator's user profile desktop (in Windows 2000), then I can start at the root of c: and do a 'dir /x'. That gives me the short name for "Documents and Settings" = "Docume~1". Then change into "Documents and Settings" and do another 'dir /x' to give me the short name of the admin's profile directory "administrator" = "admini~1", then "desktop" just = "desktop", and finally change into desktop and do a 'dir /x' for the short name of the filename "long filename.txt" = "longfi~1.txt"

Putting all that together gives me,
c:\docume~1\admini~1\ desktop\longfi~1.txt

Does that help any more?
==========================

Maybe it's the "config file .. constructing on the fly" bit that is causing issues? You are automating the construction of the config file and need to pipe in the short dir & filenames?

2007-03-27 13:05:49 · answer #1 · answered by Kevin 7 · 5 0

Short File Name

2016-12-11 14:39:45 · answer #2 · answered by Anonymous · 0 0

fedest.com, questions and answers