|
|
Joined: Dec 1999
Posts: 30,867
Master Elite Member
|
FUNCTION DirData_ToFileDate (BYREF pDirData AS DIRDATA, OPTIONAL BYVAL WhichDate AS LONG, _
OPTIONAL BYVAL DateTemplate AS STRING, OPTIONAL BYVAL TimeTemplate AS STRING, _
OPTIONAL BYVAL Flags AS LONG) AS STRING
'Purpose
' Used to parse the DateCreated value from an existing DIRDATA structure.
'Parameters
' pDirData (DIRDATA) = The structure representing the file we're working with.
' WhichDate (Optional LONG) = Determines whether the Date-Created, Date-Modifed, or Date-Accessed is returned.
' Valid values:
' 1 Return Date Created
' 2 Return Date Modified
' 3 Return Date Accessed
' Default if omitted: 1
' Default if invalid value: 1
' DateTemplate (Optional STRING) = A template used to determine the structure of the returned date.
' This template follows the same rules as the Windows GetDateFormat()#lpFormat parameter.
' Character enclosed in single quotes are literals that are retained in the output string.
' Valid values:
' d Day of month as digits with no leading zero for single-digit days.
' dd Day of month as digits with leading zero for single-digit days.
' ddd Day of week as a three-letter abbreviation.
' The function uses the LOCALE_SABBREVDAYNAME value associated with the specified locale.
' ddd Day of week as its full name. The function uses the LOCALE_SDAYNAME value associated with the specified locale.
' M Month as digits with no leading zero for single-digit months.
' MM Month as digits with leading zero for single-digit months.
' MMM Month as a three-letter abbreviation.
' The function uses the LOCALE_SABBREVMONTHNAME value associated with the specified locale.
' MMMM Month as its full name. The function uses the LOCALE_SMONTHNAME value associated with the specified locale.
' y Year as last two digits, with a leading zero for years less than 10. The same format as "yy."
' yy Year as last two digits, with a leading zero for years less than 10.
' yyyy Year represented by full four digits.
' gg Period/era string. The function uses the CAL_SERASTRING value associated with the specified locale.
' This element is ignored if the date to be formatted does not have an associated era or period string.
' Examples: "ddd',' MMM dd yy" returns "Wed, Aug 31 94"
' "yyyy" returns 1994
' To return no date value (zero-length string), use this string: "''"
' Default if omitted or zero-length: "M'/'d'/'yyyy"
' TimeTemplate (Optional STRING) = A template used to determine the structure of the returned time.
' This template follows the same rules as the Windows GetDateFormat()#lpFormat parameter.
' Character enclosed in single quotes are literals that are retained in the output string.
' Valid values:
' h Hours with no leading zero for single-digit hours; 12-hour clock
' hh Hours with leading zero for single-digit hours; 12-hour clock
' H Hours with no leading zero for single-digit hours; 24-hour clock
' HH Hours with leading zero for single-digit hours; 24-hour clock
' m Minutes with no leading zero for single-digit minutes
' mm Minutes with leading zero for single-digit minutes
' s Seconds with no leading zero for single-digit seconds
' ss Seconds with leading zero for single-digit seconds
' t One character time marker string, such as A or P
' tt Multicharacter time marker string, such as AM or PM
' Examples: "hh':'mm':'ss tt" returns "11:29:40 PM"
' "h" returns "11"
' To return no time value (zero-length string), use this string: "''"
' Default if omitted or zero-length: "h':'mm':'ss tt"
' Flags (Optional LONG) = A bit-field of behavior flags.
' Bit Fields:
' 0 If set, displays UTC time instead of local time.
' Add 1 to the value sent to this parameter to set this bit field.
' Example: DirData_ToDate(pDD, 1, "", "", 1) This will cause UTC time (created) to be displayed.
' DirData_ToDate(pDD, 1, "", "", 0) This will cause local time (created) to be displayed.
' 1 Normally, the date field is displayed just before the time field: DateTime (no space between fields).
' When this flag is set, the order of the fields is reversed: TimeDate
' This is useful when you want the time to displayed before the date.
' Add 2 to the value sent to this parameter to set this bit field:
' Example: DirDate_ToDate(pDD, 1, "", "", 2)
' 2 Suppress the default space between the returned date and time field.
' This space is added by default for convenience, but this flag allows you to have complete control
' over the format of the returned value by eliminating this space.
' Add 4 to the value sent to this parameter to set this bit field.
' Example: To set bit field 1 and 2 at the same time: DirDate_ToDate(pDD, 1, "", "", 2 + 4)
' ... All other bits are unused at this time.
' Default: 0 (zero)
'Return (STRING)
' Returns a string representing the date the file was created.
'Dependencies
' The following files must be included: WIN32API.INC
' Must run on Win 2000 Pro or higher because both API calls require it.
'Version History
' 1.00 2010.03.02 Tested by Russ Tanner on PB/CC 5.03.
LOCAL fTime AS FILETIME
LOCAL sTime AS SYSTEMTIME
LOCAL szFormat AS ASCIIZ * 64, szTime AS ASCIIZ * 64, szDate AS ASCIIZ * 64
'Default WhichDate to valid value.
WhichDate = IIF&(WhichDate < 1 OR WhichDate > 3, 1, WhichDate)
'Load the fTime structure.
'We're working with date-created.
IF WhichDate = 1 THEN
fTime.dwLowDateTime = LO(DWORD, pDirData.CreationTime)
fTime.dwHighDateTime = HI(DWORD, pDirData.CreationTime)
'We're working with date-modified.
ELSEIF WhichDate = 2 THEN
fTime.dwLowDateTime = LO(DWORD, pDirData.LastWriteTime)
fTime.dwHighDateTime = HI(DWORD, pDirData.LastWriteTime)
'We're working with date-accessed.
ELSEIF WhichDate = 3 THEN
fTime.dwLowDateTime = LO(DWORD, pDirData.LastAccessTime)
fTime.dwHighDateTime = HI(DWORD, pDirData.LastAccessTime)
END IF
'Convert the time using an API call.
FileTimeToSystemTime fTime, sTime
'Only display UTC if the corresponding flag is set.
IF ISFALSE BIT(Flags, 0) THEN
SystemTimeToTzSpecificLocalTime BYVAL %NULL, sTime, sTime 'Convert to local time
END IF
'Format the time and date.
szFormat = IIF$(LEN(TimeTemplate) > 0, TimeTemplate, "h':'mm':'ss tt")
GetTimeFormat %LOCALE_SYSTEM_DEFAULT, BYVAL %NULL, sTime, szFormat, szTime, SIZEOF (szTime)
szFormat = IIF$(LEN(DateTemplate) > 0, DateTemplate, "M'/'d'/'yyyy")
GetDateFormat %LOCALE_SYSTEM_DEFAULT, BYVAL %NULL, sTime, szFormat, szDate, SIZEOF (szDate)
'Determine the returned order of date/time based on bit-field 1
FUNCTION = IIF$(BIT(Flags, 1), szTime + IIF$(BIT(Flags, 2), "", " ") + szDate, szDate + IIF$(BIT(Flags, 2), "", " ") + szTime)
END FUNCTION
|
|
|
|
Entire Thread
|
DirData_ToFileDate
|
Russ
|
03/02/10 12:29 PM
|
|
|
|