Sign in to follow this  
Followers 0
Gringalf

Unwanted behaviour with short filenames

3 posts in this topic

This is my first post, so I should thank you for this great board and say: "Hello!"

I used the forum search but did not find what I was looking for.

The problem:

AutoIt seems to expand short names, if possible.

$file = "C:\progra~1"
If FileExists($file) Then
    MsgBox(64, "Info", "The file: <" & $file & "> exists.")
Else
    MsgBox(64, "Info", "The file: <" & $file & "> does not exist.")
EndIf

This is sample code should demonstrate the issue at least in the german version. "C:\progra~1" does not exist, but "C:\Programme" exists, so the MsgBox returns "The file: <C:\progra~1> exists.". Now, I must know if $file exists with its exact name (C:\Progra~1), not if its name could be expanded to a long filename which exists (C:\Programme). So I want the above code to reply "The file: C:\progra~1 does not exist."

My workaround to this problem is the following:

$file = "C:\progr~1"
If FileExists($file) Then
    If (StringCompare(FileGetLongName($file), $file) == 0) Then
        MsgBox(64, "Info", "The file: <" & $file & "> exists.")
    Else
        MsgBox(64, "Info", "The short filename: <" & $file & "> does not exist.")
    EndIf
Else
    MsgBox(64, "Info", "The file: <" & $file & "> does not exist.")
EndIf

Is there a more elegant solution to this problem? Maybe a general option/switch in AutoIt that I did not find? Thanks in advance!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This is my first post, so I should thank you for this great board and say: "Hello!"

I used the forum search but did not find what I was looking for.

The problem:

AutoIt seems to expand short names, if possible.

$file = "C:\progra~1"
If FileExists($file) Then
    MsgBox(64, "Info", "The file: <" & $file & "> exists.")
Else
    MsgBox(64, "Info", "The file: <" & $file & "> does not exist.")
EndIf

This is sample code should demonstrate the issue at least in the german version. "C:\progra~1" does not exist, but "C:\Programme" exists, so the MsgBox returns "The file: <C:\progra~1> exists.". Now, I must know if $file exists with its exact name (C:\Progra~1), not if its name could be expanded to a long filename which exists (C:\Programme). So I want the above code to reply "The file: C:\progra~1 does not exist."

My workaround to this problem is the following:

$file = "C:\progr~1"
If FileExists($file) Then
    If (StringCompare(FileGetLongName($file), $file) == 0) Then
        MsgBox(64, "Info", "The file: <" & $file & "> exists.")
    Else
        MsgBox(64, "Info", "The short filename: <" & $file & "> does not exist.")
    EndIf
Else
    MsgBox(64, "Info", "The file: <" & $file & "> does not exist.")
EndIf

Is there a more elegant solution to this problem? Maybe a general option/switch in AutoIt that I did not find? Thanks in advance!

Hi,

the creation of short file or directory names is by design of windows os. So there is no difference between c:\prgramme and c:\progra~1. The information is stored in ntfs file system.

If you don't need the short names ( you haven't e.g 16 Bit programs running or dos applications ), disable short filename creation.

http://support.microsoft.com/kb/210638

;-))

Stefan

Edited by 99ojo

Share this post


Link to post
Share on other sites

My feeling is that this might be a problem, specific to the filename you are using.

As far as I know "C:\progra~1" used to be the Programs (or in German: Programme) folder in MS DOS. Also, when I typed in C:\progra~1 in the windows explorer, I instantly landed in C:\Programme (German version of Windows).

If you need this search for other purposes also, try if the problem really does exist. If you only need it for this one case, you might just live best with your workaround...

Best

Christoph

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0