Problem:
GetFileTime MS API:
..........................
Retrieves the date and time that a file or directory was created, last accessed, and last modified.
SetFileTime MS API:
..........................
Sets the date and time that the specified file or directory was created, last accessed, or last modified.
Resolution:
Sample is attached ...
..........................
copy "windows.cpy".
identification division.
program-id. MSAPI-FileTime.
working-storage section.
78 CRLF value x"0D0A".
78 SEP value
"==========================================================="
& CRLF.
78 PGID value "MSAPI-GetFileTime".
78 pfx value "*--> " & PGID & ": ".
78 OK value " <OK> ".
78 KO value " <KO> ".
01 lpFileName pic x(100)
value z".\\MSAPI-FileTime.cbl".
01 dwDesiredAccess DWORD value GENERIC-ALL.
01 dwShareMode DWORD value FILE-SHARE-READ.
01 dwCreationDisposition DWORD value OPEN-EXISTING.
01 dwFlagsAndAttributes DWORD value FILE-ATTRIBUTE-NORMAL.
01 FileHandle int. *> HANDLE.
01 retBOOL BOOL.
01 lpCreationTime 1-FILETIME.
01 lpLastAccessTime 1-FILETIME.
01 lpLastWriteTime 1-FILETIME.
01 WRK-SystemTime 1-systemTime.
01 WRK-FILETIME 1-FILETIME.
procedure division.
call "cob32api"
perform MS-API-CreateFile
perform MS-API-GetFileTime
perform MS-API-GetSystemTime
perform MS-API-SetFileTime
perform MS-API-GetFileTime
perform MS-API-CloseHandle
stop run.
MS-API-CloseHandle.
*> http://msdn2.microsoft.com/en-us/library/ms724211.aspx
display SEP pfx CloseHandle with no advancing
call CloseHandle
using by value FileHandle
returning retBOOL
if retBOOL = 1FALSE display KO stop run
else display OK
end-if.
MS-API-CreateFile.
*> http://msdn2.microsoft.com/en-us/library/aa363858.aspx
display SEP pfx CreateFile with no advancing
call CreateFile
using by reference lpFileName
by value dwDesiredAccess
by value dwShareMode
by value 0 size 4
by value dwCreationDisposition
by value dwFlagsAndAttributes
by value 0 size 4
returning FileHandle
if FileHandle = INVALID-HANDLE-VALUE display KO stop run
else display OK
end-if.
MS-API-GetSystemTime.
*> http://msdn2.microsoft.com/en-us/library/ms724390.aspx
display SEP pfx GetSystemTime
call GetSystemTime
using by reference WRK-SystemTime
display SEP pfx " SystemTime "
perform DISP-SystemTime.
MS-API-SetFileTime.
initialize WRK-SystemTime
move 1901 to wyear of WRK-SystemTime
move 01 to wmonth of WRK-SystemTime
move 01 to wdayofweek of WRK-SystemTime
move 01 to wday of WRK-SystemTime
* move 00 to whour of WRK-SystemTime
* move 00 to wminute of WRK-SystemTime
* move 00 to wsecond of WRK-SystemTime
* move 00 to wmilliseconds
* of WRK-SystemTime
perform MS-API-SystemTimeToFileTime
move WRK-FILETIME
to lpCreationTime
lpLastAccessTime
lpLastWriteTime
*> http://msdn2.microsoft.com/en-us/library/ms724933.aspx
display SEP pfx SetFileTime with no advancing
call SetFileTime
using by value FileHandle
by reference lpCreationTime
by reference lpLastAccessTime
by reference lpLastWriteTime
returning retBOOL
if retBOOL = 1FALSE display KO stop run
else display OK
end-if.
MS-API-GetFileTime.
*> http://msdn2.microsoft.com/en-us/library/ms724320.aspx
display SEP pfx GetFileTime with no advancing
call GetFileTime
using by value FileHandle
by reference lpCreationTime
by reference lpLastAccessTime
by reference lpLastWriteTime
returning retBOOL
if retBOOL = 1FALSE display KO stop run
else display OK
end-if
display SEP pfx " CreationTime "
move lpCreationTime to WRK-FILETIME
perform MS-API-FileTimeToSystemTime
display SEP pfx " LastAccessTime "
move lpLastAccessTime to WRK-FILETIME
perform MS-API-FileTimeToSystemTime
display SEP pfx " LastWriteTime "
move lpLastAccessTime to WRK-FILETIME
perform MS-API-FileTimeToSystemTime
.
MS-API-SystemTimeToFileTime.
*> http://msdn2.microsoft.com/en-us/library/ms724280.aspx
display SEP pfx SystemTimeToFileTime with no advancing
call SystemTimeToFileTime
using by reference WRK-SystemTime
by reference WRK-FILETIME
returning retBOOL
if retBOOL = 1FALSE display KO stop run
else display OK
.
MS-API-FileTimeToSystemTime.
*> http://msdn2.microsoft.com/en-us/library/ms724280.aspx
display pfx FileTimeToSystemTime with no advancing
call FileTimeToSystemTime
using by reference WRK-FILETIME
by reference WRK-SystemTime
returning retBOOL
if retBOOL = 1FALSE display KO stop run
else display OK
perform DISP-SystemTime
end-if.
DISP-SystemTime.
display " wyear: " wyear of WRK-SystemTime
display " wmonth: " wmonth of WRK-SystemTime
display " wdayofweek: " wdayofweek of WRK-SystemTime
display " wday: " wday of WRK-SystemTime
display " whour: " whour of WRK-SystemTime
display " wminute: " wminute of WRK-SystemTime
display " wsecond: " wsecond of WRK-SystemTime
display " wmilliseconds: " wmilliseconds
of WRK-SystemTime
.