Crazy Eddie
(Starting to like KiXtart)
2002-11-26 11:45 PM
Need ShortFileName("File") Function

No UDF is available for this, and it would be great if it were included in the Built-in functions.

Several old utilities (ProfGen for one) choke on long file names.


kholm
(Korg Regular)
2002-11-27 12:15 AM
Re: Need ShortFileName("File") Function

If you surround the 'long' filename by double quoutes and use 'Start' the short filename will be translated correctly!

Example:
code:
Shell '%COMSPEC% /C Start ProfGen "C:\Long name for directory\Long filename.ini"'

-Erik


MightyR1
(MM club member)
2002-11-27 12:19 AM
Re: Need ShortFileName("File") Function

True,

but if you remember the inst.kix script from bbChecker, it uses addprogramitem which requires a shortname for the icon.

Will try to write a UDF for you guys.

Anyone know how shortnames are determined by the OS?


Chris S.
(MM club member)
2002-11-27 02:27 AM
Re: Need ShortFileName("File") Function

Sure...basically its first six letters of the folder (no spaces) a ~ then a number.

So...

C:\A Long Folder

would be...

C:\alongf~1


NTDOCAdministrator
(KiX Master)
2002-11-27 02:55 AM
Re: Need ShortFileName("File") Function

C:\A Long Folder
would be
C:\alongf~1

C:\A Long Folder is here
would be:
C:\alongf~2

C:\A Long Folder is here to stay
would be:
C:\alongf~3

However, here is a MS KB on the subject.
Short (8.3) File Names May Change When Copied

A DIR /X will show the short file names

FindFile/FindNextFile Query or DIR Query Does Not Return the Correct Set of Files

How to Disable Automatic Short File Name Generation
NOTE: Existing files using the short name format will still be available to 32-bit programs, but all files created after this change is implemented will be unavailable to older 16-bit programs.


Kdyer
(KiX Supporter)
2002-11-27 05:14 AM
Re: Need ShortFileName("File") Function

Profgen?

Have used it fine with LFNs..

If you are having trouble, have you tried surrounding your LFN with ""'s. In other words:

This is a long filename

to be:

"This is a long filename"

HTH,

Kent


MightyR1
(MM club member)
2002-11-27 07:40 AM
Re: Need ShortFileName("File") Function

Guys,

I knew about the ~; spaces and other illegal 8.3 chars are to be removed too. Also all dots except the last should be removed.

What puzzles me is the "MS logic" i.e. in short names for folders like "a b" and "q w".
DOn't see it...

Anyone does???


LonkeroAdministrator
(KiX Master Guru)
2002-11-27 10:17 AM
Re: Need ShortFileName("File") Function

you mean like with dir /x:
code:
27.11.2002  11:18       <KANSIO>                       .
27.11.2002 11:18 <KANSIO> ..
27.11.2002 11:18 <KANSIO> AD0949~1 a d
27.11.2002 11:17 <KANSIO> AS093A~1 a s
27.11.2002 10:05 891 ASIAKI~1.TXT Asiakirja.txt
27.11.2002 10:35 <KANSIO> BBCHEC~1 BBChecker



[ 27. November 2002, 10:18: Message edited by: Lonkero ]


JochenAdministrator
(KiX Supporter)
2002-11-27 10:23 AM
Re: Need ShortFileName("File") Function

[Eek!]

that'd make it a tiny bit harder to code the udf for it

[ 27. November 2002, 10:24: Message edited by: jpols ]


Lee Wilmott
(Starting to like KiXtart)
2002-11-27 11:25 AM
Re: Need ShortFileName("File") Function

(Crazy) Eddie,

Have a look at http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000307.

You may find it helpful.

Lee


JochenAdministrator
(KiX Supporter)
2002-11-27 11:28 AM
Re: Need ShortFileName("File") Function

Hehe,

shipping around the logical cliffs of creation by using things already available ... Cool

{My vote for that !}

[ 27. November 2002, 11:29: Message edited by: jpols ]


LonkeroAdministrator
(KiX Master Guru)
2002-11-28 12:22 AM
Re: Need ShortFileName("File") Function

already avail?
just added...
and I can't use it as it's wsh...


Sealeopard
(KiX Master)
2002-11-27 03:15 PM
Re: Need ShortFileName("File") Function

I have the same problem of not being able to use it because I actively disable the creation of DOS-compatible (short) filenames under NTFS in order to increase file I/O performance.

Crazy Eddie
(Starting to like KiXtart)
2002-11-27 03:29 PM
Re: Need ShortFileName("File") Function

Wow...thanks for the replies.

Let's take them apart:
1) The WSH option is a decent one, but I was looking for a KIX-only solution.
2) The use of double "" does not properly work for profgen. My command is "{path}profgen.exe {path}newprof.exe -P {path}my.prf {switches} -T {path}TempDir" If any of the second or more pathes have spaces, the command chokes. Quotes in a variety of ways have been tried...doesn't work. Short name pathing does work. However, as described, you can't reliably figure out MS's method for determining a short name, just by knowing the long name.
3) Dir/x works okay, execept when trying to get the short name for a directory itself. It will return the contents of the directory.
4) If a short name is not available because it has been disabled - that's a problem.

Basicly, we need KIX to query the file system/OS to return a short name (if available) for a long name provided. That's what WSH is doing in the provided example.

Great conversation!
Ed

[ 27. November 2002, 15:30: Message edited by: Crazy Eddie ]


Sealeopard
(KiX Master)
2002-11-27 03:43 PM
Re: Need ShortFileName("File") Function

Please post the PROFGEN line that doesn't work. So far, any time I've had space in a pathname I was able to use quotes to properly use the pathname.

DOS-compatible filenames are a legacy issue and one should get rid of those as fast as possible.

[ 27. November 2002, 15:44: Message edited by: sealeopard ]


Crazy Eddie
(Starting to like KiXtart)
2002-11-27 04:34 PM
Re: Need ShortFileName("File") Function

The code at this point looks like this:

code:
   IF "%USERPROFILE%"=""
$TestKey="HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ProfileReconciliation\"
$TestValue="ProfileDirectory"
$PROFILEDir=ReadValue($TestKey,$TestValue)
$USERPROFDir="$Profile"
ELSE
$USERPROFDir="%USERPROFILE%"
ENDIF

$MAPILOC=C:\scripts\OUTLOOK
COPY "$MAPILOC\OUTLOOK.PRF" "$USERPROFDir\@userid.PRF"
SHELL '$MAPILOC\PROFGEN.EXE "$MAPILOC\NEWPROF.EXE" -P "$USERPROFDir\@userid.PRF" -R -T "$USERPROFDir"'

This fails.

If you attempt to do the exact same thing in a command prompt, same effect. If you replace all of the LFNs with SFNs, it works. This is a DOS/Profgen issue, not a KIX issue.

NOTE: The reason I am using $UserProfDir for the PRF and the temp directory is to handle multiple logins on a Citrix/TS environment, to ensure the files are not overwritten by other users. (That's my attempt, anyway.)

Ed

ps: SSN-638 and SSN-751 were in my past [Smile]


LonkeroAdministrator
(KiX Master Guru)
2002-11-27 04:50 PM
Re: Need ShortFileName("File") Function

could we continue this in scripts:
http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=2&t=004001

as this problem has not so much to do with the suggestion.


MCA
(KiX Supporter)
2002-12-07 11:18 AM
Re: Need ShortFileName("File") Function

Dear,

On this forum we had made also a request about shortcut names (KIX-FUNCTION: con-
version of long/short filenames to short/long filenames
). At this moment Ruud doesn't
implement something like that.

It looks like that a lot of new suggestions are copies of old ones.
Possible that someone can reread this forum about all interesting suggestions, which
aren't implementing at this moment. As list we can ask Ruud for his comment about
it. In some situation he had return already comment on some of those oldies.
greetings.

(TO_DO)

[ 07. December 2002, 11:25: Message edited by: MCA ]


LonkeroAdministrator
(KiX Master Guru)
2002-12-08 12:00 AM
Re: Need ShortFileName("File") Function

already really many of those is included in:
http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=4;t=000282


MCA
(KiX Supporter)
2002-12-07 02:31 PM
Re: Need ShortFileName("File") Function

Dear,

We know, but it isn't in a very readable format for Ruud.
greetings.


BrianTX
(Korg Regular)
2003-01-02 06:01 PM
Re: Need ShortFileName("File") Function

Hmm.. lots of discussion on this. I would vote for a pure KiXtart solution that would return either the specific short file name of a given file, or the short file name of a given long file name provided none was present if a location was specified.

For example, given a directory with a file:

c:\howdyguys.txt -lfn
c:\howdyg~1.txt -sfn (same file)

sfn("howdyguys.txt") would return:
howdyg~1.txt

sfn("howdyguys1.txt") would also return:
howdyg~1.txt

sfn("howdyguys.txt","c:\") would return:
howdyg~1.txt (because that's the short name of the existing file with that name)

sfn("howdyguys1.txt","c:\") would return:
howdyg~2.txt (because the file doesn't exist and there is already a howdyg~1.txt)
.......

Just my 2 cents.. a UDF could be written for this as well, but I don't think it could be done purely in KiXtart (without using command prompt or WSH).

Brian


Radimus
(KiX Supporter)
2003-01-02 10:37 PM
Re: Need ShortFileName("File") Function

I can do this easily, but it will require WSHPipe

or it will turn into a big slow script...

Any interest??

basically redirecting a DIR /x $x |find $y into a variable to substr it.

[ 02. January 2003, 22:41: Message edited by: Radimus ]