B4J Question Short Filenames [My File Has A Long Name Which I Like.txt] => [MYFILE~H.txt]

rgarnett1955

Active Member
Licensed User
Longtime User
Hi All,



I wrote a program that uses File.DirApp to get the application directory. On one computer Win 64 Bit Professional. iI returned the full filename on another with same operating system it returned the short filename.

Of course the operating system can use both, but us humans have problems with this. I did a bit of Googling and found that you can control the use of long and short filenames using either a utility or a bit of registry editing. Viz:

fsUtil

fsutil 8dot3name

ftype

Registry Setting

To cut a long story short, I turned off the short filenames using:

Bash:
 title="Command to Set NTFS short filename handling;"]To disable 8.3 name creation on all NTFS partitions, type fsutil.exe behavior set disable8dot3 1 at an elevated command prompt, and then press Enter.

This operation takes effect immediately (no restart required).

Notes
 
When a volume is not specified, the operation updates the registry value:

    0 - Enable 8dot3 name creation on all volumes on the system
    1 - Disable 8dot3 name creation on all volumes on the system
    2 - Set 8dot3 name creation on a per volume basis
    3 - Disable 8dot3 name creation on all volumes except the system volume

When a volume is specified, the operation updates the individual volume's on disk flag. This operation is meaningful only if the registry value is set to 2.

    0 - Enable 8dot3 name creation on this volume
    1 - Disable 8dot3 name creation on this volume

OR

Changeing Short Fielnames in Registry:
322756 How to back up and restore the registry in Windows

    Start Regedt32.exe and locate the following registry key:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
    Select the NtfsDisable8dot3NameCreation entry.

    Note By default, the value for this entry is set to 0.
    On the Edit menu, click DWORD. Type a value of 1 in the Data field.
    Click OK and then exit Regedt32.
    Exit Windows NT, and then shut down your computer.
    Restart your computer and Windows NT.

NOTE: The change to the NtfsDisable8dot3NameCreation registry entry affects
only files, folders, and profiles that are created after the change.
Files that already exist are not affected.

Note that only files that are created after the command iS executed are affected.

I then stripped the short filenames out of my directory using:

Strip Out Short Filenames:
'Command
fsutil 8dot3name [strip] [/t] [/s] [/f] [/l [<log file.] ] [/v] <directorypath>

'Example
fsutil 8dot3name strip /l mylogfile.log /s C:\B4X\B4J


This fixed the problem.

Have a look in mylogfile.log to see what was done by this command.

WARNING

You need to be careful with this. If you have legacy software that need short filenames then you have to either turn on short filenames for all volumes or turn it on for only those volumes or directories that the legacy program uses.


Short filenames slow down the file system a bit and that's why it's often turned of on file servers. The speed difference probably won't be discernible on a workstation PC, so I wouldn't turn short filenames off to try and speed things up.
 

Jorge M A

Well-Known Member
Licensed User
File.DirApp is based on a system property. It returns the value as is.

In most cases it doesn't matter whether you hold the short name or the long name. You can use this code to get the full name:
B4X:
Sub GetCanonicalPath(Path As String) As String
Dim fileO As JavaObject
fileO.InitializeNewInstance("java.io.File", Array As Object(Path))
Return fileO.RunMethod("getCanonicalPath", Null)
End Sub
 
Upvote 0

rgarnett1955

Active Member
Licensed User
Longtime User

Hi Jorge,

I know that. I just thought people would like to know about how short file names might be managed in NTFS.

The fact that File.DirApp returns short filenames isn't documented in the B4X guides as far as I can see.

Who wants a short filename these days?

Why can't there be a in-built function to get the full filename? Then people wouldn't waste time trying to figure out what is going on. It wasted an hour of my time when I could have been producing useful code. I have an app that is displaying the file names so displaying short file names is a bummer.

How is anybody going to know what getCanonicalPath means. It's just Java Jargon. Canonical is a word that had it's origins in religion (Canon Law), nothing to do with software.

Wouldn't getLongFilename have been more descriptive?

I use B4X so I don't have to use Java. In my view Java is a mess: I'm 65 I don't have enough time left to learn it.

Best regards
Rob
 
Upvote 0

Jorge M A

Well-Known Member
Licensed User
I do understand what you're saying, and you may be right on some points.
However, with the techniques you describe you have no guarantee that Microsoft will respect the modifications you make to the OS, and that in some update it will reverse those changes and your programs will start to fail.
You have an example of different behavior, and only by checking what updates have one and another you could know what causes it:
On one computer Win 64 Bit Professional. iI returned the full filename on another with same operating system it returned the short filename.

In my view Java is a mess: ... I don't have enough time left to learn it.
I totally agree with this. That's why I trust the many experts who contribute to the forum.
Greetings and good luck.
JMA
 
Upvote 0
Top