To convert a long filename to a DOS filename (also known as an 8.3 filename) in Delphi, you can use the GetShortPathName
function from the Windows API. This function takes a long filename as input and returns the corresponding short (8.3) filename.
Here is an example of how to use the GetShortPathName
function to convert a long filename to a short filename in Delphi:
1 2 3 4 5 6 7 8 9 |
function LongToShortFilename(const LongFilename: string): string; var Buffer: array[0..MAX_PATH] of Char; begin if GetShortPathName(PChar(LongFilename), Buffer, MAX_PATH) <> 0 then Result := Buffer else Result := LongFilename; end; |
This function takes a long filename as input and returns the corresponding short filename. If the conversion fails, it returns the original long filename.
To use this function, you can simply pass in the long filename as a string and assign the returned value to a string variable. Here is an example of how to use the LongToShortFilename
function:
1 2 3 4 5 6 |
var ShortFilename: string; begin ShortFilename := LongToShortFilename(‘C:\Program Files\My Program\MyFile.txt’); // ShortFilename will contain the short version of the filename, such as ‘C:\PROGRA~1\MYPROG~1\MYFILE~1.TXT’ end; |
Leave a Reply