CONST QDIR_RQCR = CHR$(10)
CONST QDIR_BACKSLASH = CHR$(92)
CONST QDIR_MAXWORD = &HFFFF
CONST QDIR_INVALID_HANDLE_VALUE = -1
CONST QDIR_FILE_ATTRIBUTE_ARCHIVE = &H20
CONST QDIR_FILE_ATTRIBUTE_DIRECTORY = &H10
CONST QDIR_FILE_ATTRIBUTE_HIDDEN = &H2
CONST QDIR_FILE_ATTRIBUTE_NORMAL = &H80
CONST QDIR_FILE_ATTRIBUTE_READONLY = &H1
CONST QDIR_FILE_ATTRIBUTE_SYSTEM = &H4
CONST QDIR_FILE_ATTRIBUTE_TEMPORARY = &H100
CONST QDIR_FILE_ATTRIBUTE_COMPRESSED = &H800
TYPE QDIR_FILETIME
lowDateTime AS LONG
highDateTime AS LONG
END TYPE
TYPE QDIR_WIN32_FIND_DATA
attributes AS LONG
creationLowDateTime AS LONG
creationHighDateTime AS LONG
lastAccessLowDateTime AS LONG
lastAccessHighDateTime AS LONG
lastWriteLowDateTime AS LONG
lastWriteHighDateTime AS LONG
fileSizeHigh AS LONG
fileSizeLow AS LONG
dwReserved0 AS LONG
dwReserved1 AS LONG
cFileName AS STRING * 260
cAlternate AS STRING * 14
END TYPE
TYPE QDIR_SYSTEMTIME
year AS SHORT
month AS SHORT
dayOfWeek AS SHORT
day AS SHORT
hour AS SHORT
minute AS SHORT
second AS SHORT
milliseconds AS SHORT
DateTime AS DOUBLE
date AS STRING * 10
dateEU AS STRING * 10
dateAlpha AS STRING * 16
dateAlphaEU AS STRING * 15
time AS STRING * 8
timems AS STRING * 12
strDayOfWeek AS STRING * 3
nWeekDay AS STRING * 1
strMonthOfYear AS STRING * 3
END TYPE
DECLARE FUNCTION QDIR_FindFirstFile LIB "kernel32" ALIAS "FindFirstFileA" (ByRef lpFileName AS STRING, _
ByRef lpFindFileData AS QDIR_WIN32_FIND_DATA) AS LONG
DECLARE FUNCTION QDIR_FindClose LIB "kernel32" ALIAS "FindClose" (BYVAL hFindFile AS LONG) AS LONG
DECLARE FUNCTION QDIR_FindNextFile LIB "kernel32" ALIAS "FindNextFileA" (BYVAL hFindFile AS LONG, _
lpFindFileData AS QDIR_WIN32_FIND_DATA) AS LONG
DECLARE FUNCTION QDIR_FileTimeToLocalFileTime LIB "kernel32" ALIAS "FileTimeToLocalFileTime" _
(lpFileTime AS QDIR_FILETIME, lpLocalFileTime AS QDIR_FILETIME) AS LONG
DECLARE FUNCTION QDIR_FileTimeToSystemTime LIB "kernel32" ALIAS "FileTimeToSystemTime" _
(lpFileTime AS QDIR_FILETIME, lpSystemTime AS QDIR_SYSTEMTIME) AS LONG
TYPE T_FILETIMEcft
dwLowDateTime AS LONG
dwHighDateTime AS LONG
END TYPE
TYPE T_SYSTEMTIMEcft
wYear AS SHORT
wMonth AS SHORT
wDayOfWeek AS SHORT
wDay AS SHORT
wHour AS SHORT
wMinute AS SHORT
wSecond AS SHORT
wMilliseconds AS SHORT
END TYPE
CONST QDIR_GENERIC_WRITE = &H40000000
CONST QDIR_OPEN_EXISTING = 3
CONST QDIR_FILE_SHARE_READ = &H1
CONST QDIR_FILE_SHARE_WRITE = &H2
DECLARE FUNCTION QDIR_SetFileTime LIB "kernel32" ALIAS "SetFileTime" (BYVAL hFile AS LONG, _
lpCreationTime AS T_FILETIMEcft, lpLastAccessTime AS T_FILETIMEcft, _
lpLastWriteTime AS T_FILETIMEcft) AS LONG
DECLARE FUNCTION QDIR_SystemTimeToFileTime LIB "kernel32" ALIAS "SystemTimeToFileTime" _
(lpSystemTime AS T_SYSTEMTIMEcft, lpFileTime AS T_FILETIMEcft) AS LONG
DECLARE FUNCTION QDIR_CreateFile LIB "kernel32" ALIAS "CreateFileA" (ByRef lpFileName AS STRING, _
BYVAL dwDesiredAccess AS LONG, BYVAL dwShareMode AS LONG, _
BYVAL lpSecurityAttributes AS LONG, BYVAL dwCreationDisposition AS LONG, _
BYVAL dwFlagsAndAttributes AS LONG, BYVAL hTemplateFile AS LONG) AS LONG
DECLARE FUNCTION QDIR_CloseHandle LIB "kernel32" ALIAS "CloseHandle" (BYVAL hObject AS LONG) AS LONG
DECLARE FUNCTION QDIR_SetFileAttributes LIB "kernel32" ALIAS "SetFileAttributesA" _
(ByRef lpFileName AS STRING, BYVAL dwFileAttributes AS LONG) AS LONG
DECLARE SUB OnFileFound_EventTemplate
TYPE QDir EXTENDS QOBJECT
PUBLIC:
OnFileFound AS EVENT (OnFileFound_EventTemplate)
fileName AS STRING
dosFileName AS STRING
path AS STRING
pathFileName AS STRING
size AS DOUBLE
WithDotsDirs AS LONG
dateTime AS DOUBLE
time AS STRING
timems AS STRING
date AS STRING
dateEU AS STRING
dateAlpha AS STRING
dateAlphaEU AS STRING
strDayOfWeek AS STRING
strMonthOfYear AS STRING
attributes AS LONG
attributesAsString AS STRING
days(0 TO 6) AS STRING
months(1 TO 12) AS STRING
creation AS QDIR_SYSTEMTIME
lastAccess AS QDIR_SYSTEMTIME
lastWrite AS QDIR_SYSTEMTIME
flagStop AS LONG
flagShowFormStopDir AS LONG
frmDirStop AS QFORM
lblDirStop AS QLABEL
PRIVATE:
hSearch AS LONG
applicationPath AS STRING
filter AS STRING
busy AS LONG
fileStruct AS QDIR_WIN32_FIND_DATA
rejectedAttributes AS STRING
mustAttributes AS STRING
fileTime AS QDIR_FILETIME
fileLocalTime AS QDIR_FILETIME
lstDir AS QSTRINGLIST
SUB OnClic_frmDirStop
QDir.flagStop = 1
END SUB
CONSTRUCTOR
flagShowFormStopDir = 1
flagStop = 0
applicationPath = COMMAND$(0) - Application.exeName
OnFileFound = 0
busy = 0
WithDotsDirs = 1
rejectedAttributes = ""
mustAttributes = ""
days(0) = "Sunday"
days(1) = "Monday"
days(2) = "Tuesday"
days(3) = "Wednesday"
days(4) = "Thursday"
days(5) = "Friday"
days(6) = "Saturday"
months(1) = "January"
months(2) = "February"
months(3) = "March"
months(4) = "April"
months(5) = "May"
months(6) = "June"
months(7) = "July"
months(8) = "August"
months(9) = "September"
months(10) = "October"
months(11) = "November"
months(12) = "December"
frmDirStop.top = 40
frmDirStop.Left = 40
frmDirStop.Width = 400
frmDirStop.Height = 200
frmDirStop.COLOR = 0
frmDirStop.Visible = 0
frmDirStop.BorderStyle = 0
lblDirStop.Align = 5
lblDirStop.Autosize = 0
lblDirStop.Alignment = 2
lblDirStop.LabelStyle = 1
lblDirStop.Layout = 2
lblDirStop.PARENT = QDir.frmDirStop
lblDirStop.OnClick = QDir.OnClic_frmDirStop
lblDirStop.Font.COLOR = &H60FF60
lblDirStop.Font.Size = 16
lblDirStop.Font.Bold = True
lblDirStop.CAPTION = CHR$(10) & "CLIC ME TO ABORT" & CHR$(10) & CHR$(10) & " DIRECTORY SCANNING"
END CONSTRUCTOR
WITH QDir
PRIVATE:
FUNCTION CheckAttributes AS LONG
IF .rejectedAttributes <> "" THEN
IF (INSTR(.rejectedAttributes, "0") AND .fileStruct.attributes = 0) THEN _
Result = 0:EXIT FUNCTION
IF (INSTR(.rejectedAttributes, "A") AND (.fileStruct.attributes AND QDIR_FILE_ATTRIBUTE_ARCHIVE) > 0) THEN _
Result = 0:EXIT FUNCTION
IF (INSTR(.rejectedAttributes, "D") AND (.fileStruct.attributes AND QDIR_FILE_ATTRIBUTE_DIRECTORY) > 0) THEN _
Result = 0:EXIT FUNCTION
IF (INSTR(.rejectedAttributes, "H") AND (.fileStruct.attributes AND QDIR_FILE_ATTRIBUTE_HIDDEN) > 0) THEN _
Result = 0:EXIT FUNCTION
IF (INSTR(.rejectedAttributes, "N") AND (.fileStruct.attributes AND QDIR_FILE_ATTRIBUTE_NORMAL) > 0) THEN _
Result = 0:EXIT FUNCTION
IF (INSTR(.rejectedAttributes, "R") AND (.fileStruct.attributes AND QDIR_FILE_ATTRIBUTE_READONLY) > 0) THEN _
Result = 0:EXIT FUNCTION
IF (INSTR(.rejectedAttributes, "S") AND (.fileStruct.attributes AND QDIR_FILE_ATTRIBUTE_SYSTEM) > 0) THEN _
Result = 0:EXIT FUNCTION
IF (INSTR(.rejectedAttributes, "T") AND (.fileStruct.attributes AND QDIR_FILE_ATTRIBUTE_TEMPORARY) > 0) THEN _
Result = 0:EXIT FUNCTION
IF (INSTR(.rejectedAttributes, "C") AND (.fileStruct.attributes AND QDIR_FILE_ATTRIBUTE_COMPRESSED) > 0) THEN _
Result = 0:EXIT FUNCTION
END IF
IF .mustAttributes <> "" THEN
IF (INSTR(.mustAttributes, "0") AND .fileStruct.attributes <> 0) THEN _
Result = 0:EXIT FUNCTION
IF (INSTR(.mustAttributes, "A") AND (.fileStruct.attributes AND QDIR_FILE_ATTRIBUTE_ARCHIVE) = 0) THEN _
Result = 0:EXIT FUNCTION
IF (INSTR(.mustAttributes, "D") AND (.fileStruct.attributes AND QDIR_FILE_ATTRIBUTE_DIRECTORY) = 0) THEN _
Result = 0:EXIT FUNCTION
IF (INSTR(.mustAttributes, "H") AND (.fileStruct.attributes AND QDIR_FILE_ATTRIBUTE_HIDDEN) = 0) THEN _
Result = 0:EXIT FUNCTION
IF (INSTR(.mustAttributes, "N") AND (.fileStruct.attributes AND QDIR_FILE_ATTRIBUTE_NORMAL) = 0) THEN _
Result = 0:EXIT FUNCTION
IF (INSTR(.mustAttributes, "R") AND (.fileStruct.attributes AND QDIR_FILE_ATTRIBUTE_READONLY) = 0) THEN _
Result = 0:EXIT FUNCTION
IF (INSTR(.mustAttributes, "S") AND (.fileStruct.attributes AND QDIR_FILE_ATTRIBUTE_SYSTEM) = 0) THEN _
Result = 0:EXIT FUNCTION
IF (INSTR(.mustAttributes, "T") AND (.fileStruct.attributes AND QDIR_FILE_ATTRIBUTE_TEMPORARY) = 0) THEN _
Result = 0:EXIT FUNCTION
IF (INSTR(.mustAttributes, "C") AND (.fileStruct.attributes AND QDIR_FILE_ATTRIBUTE_COMPRESSED) = 0) THEN _
Result = 0:EXIT FUNCTION
END IF
Result = 1
END FUNCTION
FUNCTION DwToDbl (iDw AS LONG) AS DOUBLE
DEFDBL dwTmp, dbl2exp31
dwTmp = iDw
dbl2exp31 = 2147483648
IF dwTmp < 0 THEN
dwTmp = dwTmp SHL 1
dwTmp = dwTmp SHR 1
Result = dbl2exp31 + dwTmp
ELSE
Result = dwTmp
END IF
END FUNCTION
FUNCTION RQdwXdw (dwHigh AS LONG, dwLow AS LONG) AS DOUBLE
DEFDBL dbl2exp32
dbl2exp32 = 4294967296
Result = .dwToDbl(dwLow) + (dbl2exp32 * .dwToDbl(dwHigh))
END FUNCTION
FUNCTION ExtractFilename AS STRING
DEFINT iPtr
iPtr = INSTR (.fileStruct.cFilename, CHR$(0))
Result = LEFT$(.fileStruct.cFilename, iPtr - 1)
END FUNCTION
FUNCTION ExtractDosFilename AS STRING
DEFINT iPtr
iPtr = INSTR (.fileStruct.cAlternate, CHR$(0))
Result = LEFT$(.fileStruct.cAlternate, iPtr - 1)
END FUNCTION
FUNCTION ElementDateTimeFormat (DATA AS SHORT) AS STRING
IF DATA < 10 THEN Result = "0" & STR$(DATA):EXIT FUNCTION
Result = STR$(DATA)
END FUNCTION
FUNCTION MsFormat (DATA AS SHORT) AS STRING
IF DATA < 10 THEN Result = "00" & STR$(DATA):EXIT FUNCTION
IF DATA < 100 THEN Result = "0" & STR$(DATA):EXIT FUNCTION
Result = STR$(DATA)
END FUNCTION
FUNCTION YearFormat (DATA AS SHORT) AS STRING
IF DATA < 10 THEN Result = "000" & STR$(DATA):EXIT FUNCTION
IF DATA < 100 THEN Result = "00" & STR$(DATA):EXIT FUNCTION
IF DATA < 1000 THEN Result = "0" & STR$(DATA):EXIT FUNCTION
Result = STR$(DATA)
END FUNCTION
SUB ConvertTimeToStrings (iSystemTime AS QDIR_SYSTEMTIME)
iSystemTime.dateEU = .ElementDateTimeFormat(iSystemTime.Day) & "/" _
& .ElementDateTimeFormat(iSystemTime.Month) & "/" _
& .YearFormat(iSystemTime.Year)
iSystemTime.date = .ElementDateTimeFormat(iSystemTime.Month) & "/" _
& .ElementDateTimeFormat(iSystemTime.Day) & "/" _
& .YearFormat(iSystemTime.Year)
iSystemTime.timems = .ElementDateTimeFormat(iSystemTime.Hour) & ":" _
& .ElementDateTimeFormat(iSystemTime.Minute) & ":" _
& .ElementDateTimeFormat(iSystemTime.Second) & "." _
& .MsFormat(iSystemTime.Milliseconds)
iSystemTime.Time = LEFT$(iSystemTime.timems, 8)
iSystemTime.nWeekDay = STR$(iSystemTime.DayOfWeek)
iSystemTime.strDayOfWeek = LEFT$(.days(iSystemTime.DayOfWeek), 3)
iSystemTime.strMonthOfYear = LEFT$(.months(iSystemTime.Month), 3)
iSystemTime.dateAlphaEU = iSystemTime.strDayOfWeek & " " _
& .ElementDateTimeFormat(iSystemTime.Day) & " " _
& iSystemTime.strMonthOfYear & " " _
& .YearFormat(iSystemTime.Year)
iSystemTime.dateAlpha = iSystemTime.strDayOfWeek & " " _
& iSystemTime.strMonthOfYear & " "_
& .ElementDateTimeFormat(iSystemTime.Day) & ", " _
& .YearFormat(iSystemTime.Year)
END SUB
SUB GetFileDatas
DEFSTR sTmp
.fileName = .ExtractFileName
.dosFileName = .ExtractDosFileName
.pathFileName = .path & .fileName
.size = .RQdwXdw(.fileStruct.fileSizeHigh, .fileStruct.fileSizeLow)
.creation.DateTime = .RQdwXdw(.fileStruct.creationHighDateTime, _
.fileStruct.creationLowDateTime)
.fileTime.lowDateTime = .fileStruct.creationLowDateTime
.fileTime.highDateTime = .fileStruct.creationHighDateTime
QDIR_FileTimeToLocalFileTime(.fileTime, .fileLocalTime)
QDIR_FileTimeToSystemTime(.fileLocalTime, .creation)
.ConvertTimeToStrings (QDir.creation)
.lastAccess.DateTime = .RQdwXdw(.fileStruct.lastAccessHighDateTime, _
.fileStruct.lastAccessLowDateTime)
.fileTime.lowDateTime = .fileStruct.lastAccessLowDateTime
.fileTime.highDateTime = .fileStruct.lastAccessHighDateTime
QDIR_FileTimeToLocalFileTime(.fileTime, .fileLocalTime)
QDIR_FileTimeToSystemTime(.fileLocalTime, .lastAccess)
.ConvertTimeToStrings (QDir.lastAccess)
.lastWrite.DateTime = .RQdwXdw(.fileStruct.lastWriteHighDateTime, _
.fileStruct.lastWriteLowDateTime)
.fileTime.lowDateTime = .fileStruct.lastWriteLowDateTime
.fileTime.highDateTime = .fileStruct.lastWriteHighDateTime
QDIR_FileTimeToLocalFileTime(.fileTime, .fileLocalTime)
QDIR_FileTimeToSystemTime(.fileLocalTime, .lastWrite)
.ConvertTimeToStrings (QDir.lastWrite)
.dateTime = .lastWrite.DateTime
.date = .lastWrite.date
.dateEU = .lastWrite.dateEU
.dateAlpha = .lastWrite.dateAlpha
.dateAlphaEU = .lastWrite.dateAlphaEU
.time = .lastWrite.time
.timems = .lastWrite.timems
.strDayOfWeek = .lastWrite.strDayOfWeek
.strMonthOfYear = .lastWrite.strMonthOfYear
.attributes = .fileStruct.Attributes
sTmp = ""
IF .attributes AND QDIR_FILE_ATTRIBUTE_ARCHIVE THEN sTmp = sTmp & "A"
IF .attributes AND QDIR_FILE_ATTRIBUTE_DIRECTORY THEN sTmp = sTmp & "D"
IF .attributes AND QDIR_FILE_ATTRIBUTE_HIDDEN THEN sTmp = sTmp & "H"
IF .attributes AND QDIR_FILE_ATTRIBUTE_NORMAL THEN sTmp = sTmp & "N"
IF .attributes AND QDIR_FILE_ATTRIBUTE_READONLY THEN sTmp = sTmp & "R"
IF .attributes AND QDIR_FILE_ATTRIBUTE_SYSTEM THEN sTmp = sTmp & "S"
IF .attributes AND QDIR_FILE_ATTRIBUTE_TEMPORARY THEN sTmp = sTmp & "T"
IF .attributes AND QDIR_FILE_ATTRIBUTE_COMPRESSED THEN sTmp = sTmp & "C"
IF sTmp = "" THEN sTmp = "0"
.attributesAsString = sTmp
END SUB
PUBLIC:
SUB Dir (sPathFilter AS STRING, sRejectedAttributes AS STRING, sMustAttributes AS STRING)
DEFSTR aPathFilter, pathFilter
DEFINT iPtr, hTmp, iFileFound
IF .busy = 0 THEN
.busy = 1
.flagStop = 0
IF .flagShowFormStopDir <> 0 THEN .frmDirStop.Show
.rejectedAttributes = UCASE$(sRejectedAttributes)
.mustAttributes = UCASE$(sMustAttributes)
pathFilter = sPathFilter
pathFilter = REPLACESUBSTR$(pathFilter, "/", CHR$(92))
IF LEFT$(pathFilter, 1) = QDIR_BACKSLASH THEN pathFilter = MID$(pathFilter, 2)
iPtr = RInstr(pathFilter, QDIR_BACKSLASH)
.path = LEFT$(pathFilter, iPtr)
.filter = MID$(pathFilter, iptr + 1)
IF INSTR(pathFilter, ":") = 0 THEN .path = .applicationPath & .path
hTmp = QDIR_FindFirstFile (pathFilter, .fileStruct)
IF hTmp <> -1 THEN
iFileFound = hTmp
WHILE iFileFound <> 0
IF .CheckAttributes <> 0 THEN
.GetFileDatas
IF .WithDotsDirs = 1 THEN
CALLFUNC .OnFileFound
ELSE
IF (.fileName <> "." AND .fileName <> "..") THEN CALLFUNC .OnFileFound
END IF
END IF
iFileFound = QDIR_FindNextFile (hTmp, .fileStruct)
IF .flagStop <> 0 THEN EXIT WHILE
DOEVENTS
WEND
END IF
.frmDirStop.Visible = 0
QDIR_FindClose (hTmp)
.busy = 0
ELSE
SHOWMESSAGE ("QDIR ERROR : QDIR ALREADY SEARCHING,\nPROGRAMMER SHOULD HAVE CREATE ANOTHER QDIR")
END IF
END SUB
SUB Dirs (sPathFilter AS STRING, sRejectedAttributes AS STRING, sMustAttributes AS STRING)
DEFSTR aPathFilter, pathFilter
DEFINT iPtr, hTmp, iFileFound, iLstDirIndex, N
IF .busy = 0 THEN
.busy = 1
.flagStop = 0
IF .flagShowFormStopDir <> 0 THEN .frmDirStop.Show
.rejectedAttributes = UCASE$(sRejectedAttributes)
.mustAttributes = UCASE$(sMustAttributes)
pathFilter = sPathFilter
pathFilter = REPLACESUBSTR$(pathFilter, "/", CHR$(92))
IF LEFT$(pathFilter, 1) = QDIR_BACKSLASH THEN pathFilter = MID$(pathFilter, 2)
iPtr = RInstr(pathFilter, QDIR_BACKSLASH)
.path = LEFT$(pathFilter, iPtr)
.filter = MID$(pathFilter, iptr + 1)
IF INSTR(pathFilter, ":") = 0 THEN .path = .applicationPath & .path
.lstDir.Additems (.path)
iLstDirIndex = 0
WHILE .lstDir.ItemCount > iLstDirIndex
.path = .lstDir.Item(iLstDirIndex)
pathFilter = .path & "*.*"
hTmp = QDIR_FindFirstFile (pathFilter, .fileStruct)
IF hTmp <> -1 THEN
iFileFound = hTmp
N = 1
WHILE iFileFound <> 0
IF (.fileStruct.attributes AND QDIR_FILE_ATTRIBUTE_DIRECTORY) <> 0 THEN
iPtr = INSTR (.fileStruct.cFilename, CHR$(0))
.fileName = LEFT$(.fileStruct.cFilename, iPtr - 1)
SELECT CASE .fileName
CASE "."
CASE ".."
CASE ELSE
.lstDir.InsertItem (iLstDirIndex + N, .path & .filename & QDIR_BACKSLASH)
INC (N)
END SELECT
END IF
iFileFound = QDIR_FindNextFile (hTmp, .fileStruct)
IF .flagStop <> 0 THEN EXIT WHILE
DOEVENTS
WEND
END IF
QDIR_FindClose (hTmp)
pathFilter = .path & .filter
hTmp = QDIR_FindFirstFile (pathFilter, .fileStruct)
IF (hTmp <> -1 AND .flagStop = 0 ) THEN
iFileFound = hTmp
WHILE iFileFound <> 0
IF .CheckAttributes <> 0 THEN
.GetFileDatas
IF .WithDotsDirs = 1 THEN
CALLFUNC .OnFileFound
ELSE
IF (.fileName <> "." AND .fileName <> "..") THEN CALLFUNC .OnFileFound
END IF
END IF
iFileFound = QDIR_FindNextFile (hTmp, .fileStruct)
DOEVENTS
WEND
END IF
QDIR_FindClose (hTmp)
IF .flagStop <> 0 THEN EXIT WHILE
INC(iLstDirIndex)
DOEVENTS
WEND
.frmDirStop.Visible = 0
.lstDir.Clear
.busy = 0
ELSE
SHOWMESSAGE ("QDIR ERROR : QDIR ALREADY SEARCHING,\nPROGRAMMER SHOULD HAVE CREATE ANOTHER QDIR")
END IF
END SUB
FUNCTIONI ChangeFileDateAndTime ( ... ) AS LONG
DEFINT iHandle, N
DEFINT dateTime(1 TO 6) = {1985, 8, 23, 22, 10, 12}
DEFSTR pathFileName, whichTimes, cftErr
DIM bufferFileTime AS T_FILETIMEcft
DIM systemTime AS T_SYSTEMTIMEcft
cftErr = ""
IF PARAMSTRCOUNT > 0 THEN
pathFileName = PARAMSTR$(1)
ELSE
cftErr = "No FileName Provided"
END IF
IF cftErr <> "" THEN GOTO cftError
IF PARAMSTRCOUNT > 1 THEN whichTimes = PARAMSTR$(2)
iHandle = QDIR_CreateFile(pathFileName, QDIR_GENERIC_WRITE, (QDIR_FILE_SHARE_READ OR QDIR_FILE_SHARE_WRITE), _
0, QDIR_OPEN_EXISTING, 0, 0)
IF iHandle = 0 THEN cftErr = "File Not Found":GOTO cftError
cftErr = ""
FOR N = 1 TO 6
IF PARAMVALCOUNT > N - 1 THEN
dateTime(N) = PARAMVAL(N)
ELSE
cftErr = STR$(N - 1) & " Numeric Param(s) Recieved, 6 Awaited"
EXIT FOR
END IF
NEXT N
IF cftErr <> "" THEN GOTO cftError
systemTime.wYear = dateTime(1)
systemTime.wMonth = dateTime(2)
systemTime.wDay = dateTime(3)
systemTime.wHour = dateTime(4)
systemTime.wMinute = dateTime(5)
systemTime.wSecond = dateTime(6)
systemTime.wMilliseconds = 333
QDIR_SystemTimeToFileTime (systemTime, bufferFileTime)
IF INSTR(UCASE$(whichTimes), "CRE") THEN
IF QDIR_SetFileTime (iHandle, bufferFileTime, 0, 0) <> 1 THEN cftErr = "Problem in Writing CreationTime"
END IF
IF cftErr <> "" THEN GOTO cftError
IF INSTR(UCASE$(whichTimes), "ACC") THEN
IF QDIR_SetFileTime (iHandle, 0, bufferFileTime, 0) <> 1 THEN cftErr = "Problem in Writing lastAccessTime"
END IF
IF cftErr <> "" THEN GOTO cftError
IF (INSTR(UCASE$(whichTimes), "WRI") OR whichTimes = "") THEN
IF QDIR_SetFileTime (iHandle, 0, 0, bufferFileTime) <> 1 THEN cftErr = "Problem in Writing lastWriteTime"
END IF
IF cftErr <> "" THEN GOTO cftError
IF iHandle THEN QDIR_CloseHandle iHandle
Result = 1
EXIT FUNCTIONI
cftError:
Result = 0
IF iHandle THEN QDIR_CloseHandle iHandle
SHOWMESSAGE ("While Changing File Date and/or Time : " & QDIR_RQCR & " " & cftErr)
END FUNCTIONI
FUNCTION ChangeFileAttributes (sPathFileName AS STRING, attributesAsString AS STRING) AS LONG
DEFINT iAttributes
DEFSTR pathFileName
pathFileName = sPathFileName
iAttributes = 0
attributesAsString = UCASE$(AttributesAsString)
IF INSTR(attributesAsString, "A") THEN iAttributes = iAttributes + QDIR_FILE_ATTRIBUTE_ARCHIVE
IF INSTR(attributesAsString, "D") THEN iAttributes = iAttributes + QDIR_FILE_ATTRIBUTE_DIRECTORY
IF INSTR(attributesAsString, "H") THEN iAttributes = iAttributes + QDIR_FILE_ATTRIBUTE_HIDDEN
IF INSTR(attributesAsString, "N") THEN iAttributes = iAttributes + QDIR_FILE_ATTRIBUTE_NORMAL
IF INSTR(attributesAsString, "R") THEN iAttributes = iAttributes + QDIR_FILE_ATTRIBUTE_READONLY
IF INSTR(attributesAsString, "S") THEN iAttributes = iAttributes + QDIR_FILE_ATTRIBUTE_SYSTEM
IF INSTR(attributesAsString, "T") THEN iAttributes = iAttributes + QDIR_FILE_ATTRIBUTE_TEMPORARY
IF INSTR(attributesAsString, "C") THEN iAttributes = iAttributes + QDIR_FILE_ATTRIBUTE_COMPRESSED
Result = QDIR_SetFileAttributes (pathFileName, iAttributes)
END FUNCTION
END WITH
END TYPE
|
|