Older Version Newer Version

Alyce Alyce Dec 29, 2011

GetShortPathNameA

- Alyce Alyce
GetShortPathNameA | DOS 8.3 Filenames | Demo
Some text below is copied from the Microsoft Developers Network Library.

For an eBook or printed book on using the API with Liberty BASIC, see:
APIs for Liberty BASIC


DOS 8.3 Filenames

In DOS operating systems, filenames were limited to 8 characters and extensions were limited to 3 characters. Some API functions require filenames in this format. A long filename can be converted to a short filename with GetShortPathNameA

To learn more about 8.3 filenames:
8.3 Filenames at Wikipedia

Demo

 filedialog "Open","*.*",file$ 
if file$="" then end

'use function with null short name argument
'first to determine size of buffer needed
calldll #kernel32, "GetShortPathNameA",_
file$ as ptr,_ 'long filename
_NULL as long,_ 'short filename argument, null to get length of buffer
0 as long,_ 'length of buffer, null to get length of buffer
length as ulong 'required length of buffer

'create a string buffer of the correct length:
shortfile$=space$(length)+chr$(0)

calldll #kernel32, "GetShortPathNameA",_
file$ as ptr,_ 'long filename
shortfile$ as ptr,_ 'short filename
length as long,_ 'length of buffer
result as ulong

print "Long filename is "; file$
print "Length of buffer for short filename is ";length
print "Short filename is ";shortfile$

GetShortPathNameA | DOS 8.3 Filenames | Demo