Sometimes you get a short file name (including short path) from somewhere,
e.g. from "ParamStr". Or you get a file name, and you just want to make
sure that it is really completely in long format. Now you might want to say:
Why not using that "GetFullPathName" API, it looks promising! It really does,
but if you tried it, you'll know that it doesn't work as expected. In win98
and win2000 you can use the brand new API "GetLongPathName", but you surely
want your programs to run under win95 and winNT4, too. So forget it again.
The solution is explained
here
and realized (and made better) in my function "GetLongFileName".
At other times you need to convert a long file name (including path) to a
short one (8.3 format). E.g. if you want to call CreateProcess to start a
16-bit program together with a file that is saved in a location, which is not
8.3-compatible. In such a case you can use my function "GetShortFileName",
which converts the file name and the full path to 8.3 format.
|
function GetLongFileName (fileName: string) : string;
function GetShortFileName (fileName: string) : string;
GetShortFileName('C:\Program Files\Example File.txt') -> 'C:\Progra~1\Exampl~1.txt'
GetLongFileName ('C:\Progra~1\Exampl~1.txt' ) -> 'C:\Program Files\Example File.txt'
|
|
Most *.dll and some *.exe files offer file version information. This info is
quite useful, if you want to know which file is newer, because sometimes the
file time stamp is the time when you installed the dll on your harddisk
instead of the time, when the dll was compiled.
The function "GetFileVersion" gives you the file version information as an
int64. This is very comfortable for direct comparisons. If you want to have
the version information in form of a nice display string, just call
"FileVersionToStr", giving in the int64 value that you got from
"GetFileVersion".
|
function GetFileVersion (file_ : string) : int64;
function GetFileVersionStr (file_ : string) : string;
function FileVersionToStr (version : int64 ) : string;
function CheckDllUpdate : boolean;
var version1, version2 : int64;
begin
DownloadFile('www.yourSite.com/example.dll', 'c:\yourProgram\download\');
version1 := GetFileVersion('c:\yourProgram\example.dll');
version2 := GetFileVersion('c:\yourProgram\download\example.dll');
result := version2 > version1;
if result then begin
CopyFile('c:\yourProgram\download\example.dll', 'c:\yourProgram\example.dll', false);
ShowMessage('The file example.dll was renewed, the new version is ' +
FileVersionToStr(version2) + '.');
end;
end;
|
|