News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

File And System Dates

Started by kevin, February 25, 2008, 10:36:53 AM

Previous topic - Next topic

kevin

 File And System Dates

  This example lets you get / set  File Creation / Last Access & Write Dates on files.



PlayBASIC Code: [Select]
; PROJECT : File_Dates_And_System_Time
; AUTHOR : Kevin Picone
; CREATED : 2/25/2008
; EDITED : 2/26/2008
; ---------------------------------------------------------------------


; *=-----------------------------------------------------------------=*
;
; >> File Creation/Last Access & Write Dates V001 <<
;
; By Kevin Picone
;
; (c) copyright 2008 by Kevin Picone, All Rights Reserved
;
; *=-----------------------------------------------------------------=*
; www.underwaredesign.com - www.PlayBasic.com
; *=-----------------------------------------------------------------=*




linkDll "kernel32"

APICreateFile(FileName$, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile) alias "CreateFileA" as integer
APICloseHandle(hFile) alias "CloseHandle" as integer

GetLocalTime(SYSTEMTIME_Pointer) alias "GetLocalTime" as integer
GetSystemTime(SYSTEMTIME_Pointer) alias "GetSystemTime" as integer
GetTimeZoneInformation(TIMEZONE_POINTER) alias "GetTimeZoneInformation" as integer

; Convert System Time To File Time and back again
SystemTimeToFileTime(SYSTEMTIME_Pointer,FILETIME_POINTER) alias "SystemTimeToFileTime" as integer
FileTimeToSystemTime(FILETIME_POINTER,SYSTEMTIME_Pointer) alias "FileTimeToSystemTime" as integer

; Set/Get The FileTimes
SetFileTime(hFile,CreationTime_FILETIME_POINTER,LastAccessTime_FILETIME_Pointer,LastWriteTime_FILETIME_Pointer) alias "SetFileTime" as integer
GetFileTime(hFile,CreationTime_FILETIME_POINTER,LastAccessTime_FILETIME_Pointer,LastWriteTime_FILETIME_Pointer) alias "GetFileTime" as integer

EndLinkDll




; Build the SYSTEM TIME STRUCTURE
acset =0
Constant SYSTEMTIME_wYear =ac(2)
Constant SYSTEMTIME_wMonth =ac(2);
Constant SYSTEMTIME_wDayOfWeek =ac(2);
Constant SYSTEMTIME_wDay =ac(2)
Constant SYSTEMTIME_wHour =ac(2)
Constant SYSTEMTIME_wMinute =ac(2)
Constant SYSTEMTIME_wSecond =ac(2)
Constant SYSTEMTIME_wMilliseconds =ac(2)
Constant SYSTEMTIME_StructSize =ac(1)


; Build the FILE TIME STRUCTURE
acset =0
Constant FILETIME_dwLowDate =ac(4)
Constant FILETIME_dwHighDate =ac(4)
Constant FILETIME_StructSize =ac(1)



; Create File Access Types
Constant OPEN_EXISTING = 3
Constant CREATE_ALWAYS = 2
Constant OPEN_ALWAYS = 4
Constant FILE_SHARE_READ = $1
Constant FILE_SHARE_WRITE = $2

Constant GENERIC_WRITE = $40000000
Constant GENERIC_READ = $80000000

Constant INVALID_HANDLE_VALUE= -1



; Alloc a Bank to hold the ST structure
SysTime=NewBank(SYSTEMTIME_StructSize)

; Alloc a Bank to hold the FILETIME structure
FileTime=NewBank(FILETIME_StructSize)


; Allocate some Banks (memory) for FILETIME and SYSTEMTIME structures
FileCreationTime=NewBank(FILETIME_StructSize)
FileCreationSystemTime=NewBank(SYSTEMTIME_StructSize)


; Filename of
Filename$="C:\Testing_Changing_File_Dates.txt"

; Make a file
if FileExist(BackupFilename$) then DeleteFile BackupFilename$
Makefile BackupFilename$,40000


; get the Files Current Creation/Last access & Last Write Dates
GetFileCreationTime(filename$,getBankPtr(FileCreationTime))
FileTimeToSystemTime(getBankPtr(FileCreationTime),getBankPtr(FileCreationSystemTime))
Print "File Creation Time"
ShowSystemTime(FileCreationSystemTime)

GetFileLastAccessTime(filename$,getBankPtr(FileCreationTime))
FileTimeToSystemTime(getBankPtr(FileCreationTime),getBankPtr(FileCreationSystemTime))
Print "File Last Access Time"
ShowSystemTime(FileCreationSystemTime)

GetFileLastWriteTime(filename$,getBankPtr(FileCreationTime))
FileTimeToSystemTime(getBankPtr(FileCreationTime),getBankPtr(FileCreationSystemTime))
Print "File Last Write Time"
ShowSystemTime(FileCreationSystemTime)


print "-------------------------------------------"

; Build a new File Creation System Time
SetST_DateString("1 feb 1999",FileCreationSystemTime)
SetST_TimeString("02:02:44 AM",FileCreationSystemTime)

; Show it
ShowSystemTime(FileCreationSystemTime)

; Convert SYSTEM Time to FILE TIME
SystemTimeToFileTime(getBankPtr(FileCreationSystemTime),getBankPtr(FileCreationTime))

; Set the CREATION DATE
SetFileCreationTime(filename$,getBankPtr(FileCreationTime))
SetFileLastAccessTime(filename$,getBankPtr(FileCreationTime))
SetFileLastWriteTime(filename$,getBankPtr(FileCreationTime))


Sync
waitkey



; Set App's frame Rate
SetFps 50


; Start of Do/Loop
Do
Cls 0

if SysTime
Login required to view complete source code



----- [ Keywords ] -------------------------------------------------------------------------
 File - Date - Time

  PlayBASIC Documentation - FILE COMMANDS