Previous Topic: SetFileAttributes - Set the File AttributesNext Topic: Icon Functions


SetFileTime - Set the File or Directory Timestamps

Valid on NetWare, Symbian OS, UNIX, Windows and Windows CE

The SetFileTime function sets the timestamps of a file or directory.

This file content function has the format:

SetFileTime(fileName as string, dateAndTime as DateTime, Type as integer) as Boolean
SetFileTime(fileName as string, dateAndTime as DateTime) as Boolean
fileName

Specifies the name of the file for which the date and time is to be modified.

dateAndTime

Identifies the new date and time to be set.

Type

Value 0; Creation date and time will be modified (default).

Value 1; Last access file date and time will be modified.

Value 2; Last modified file date and time will be modified.

Value 3; Creation, last access, and final write date and time will be modified.

On successful completion, the function returns TRUE; otherwise, it returns FALSE.

Example: SetFileTime function

Rem modify write time
Dim newTime as DateTime
newTime.year = 1999
newTime.month = 12
newTime.day = 31
newTime.hour = 23
newTime.minute = 59
newTime.second = 59
If Not(SetFileTime("c:\autoexec.bat",newTime,2)) Then
	Print ("SetFileTime failed")
	Exit
End If

Read and Compare File Versions

You can read and compare the version information of any file using DMScript functions. For example, you can read and compare the version of dmscript.exe to verify whether the script is running on the desired version of DMScript.

GetFileInfo

The GetFileInfo function reads the file information of a given file. You can use the retrieved file information in other functions such as CompareVersions.

This function has the following format:

GetFileInfo (option as string, filename as string, result as string) as boolean

Example: GetFileInfo

getfileinfo("version","dmscript.exe",version)

Input Parameters

This function has the following input parameters:

Option

Specifies the file information you want to retrieve. You can specify one of the following options:

"version"

Retrieves the complete file version string in the format major.minor.patch.build. Example: "12.5.0.1234"

"major"

Retrieves the major version number of the file.

"minor"

Retrieves the minor version number of the file.

"patch"

Retrieves the patch number of the file.

"build"

Retrieves the build number of the file.

"desc"

Retrieves the file description (Windows only).

"ext"

Retrieves the file extension.

"filename"

Retrieves the file name from a path name without the extension.

Result

Specifies a string variable that holds the result returned by the function.

Return Values

If the function is able to retrieve the file information, it returns true.

CompareVersions

The CompareVersions function compares two file versions and returns whether they are identical. This function has the following format:

CompareVersions (version1 as string, version2 as string)  as integer

Example: CompareVersions

CompareVersions ("12.5.1.4", "12.5.0.3")

Input Parameters

This function has the following input parameters:

version1 and version2

Specifies the versions of the file you want to compare. You can specify any number of version identification items in the version string. For example, you can specify the version string using the major.minor.patch.build format or just the major.minor format. The version numbers can be separated by dots, spaces, or commas. If one version string has more identification items than the other version string, the missing items are replaced with zero at the time of comparison. For example, CompareVersions ("12.5.180.123", "12.5") is treated as CompareVersions ("12.5.180.123", "12.5.0.0").

Return Values

The function returns one of the following predefined integer constants:

ECVEQUAL (0)

Indicates that the versions are equal.

ECVGREATERTHAN (1)

Indicates that version 1 is greater than version 2.

ECVLESSTHAN (-1)

Indicates that version 1 is lower than version 2.

ECVINVALID (2)

Indicates that one or both of the version strings is blank or contains a non-numeric value.