Re: Das Dateidatum manuel aendern
Verfasst: 28.03.2012 22:58
Überprüfe mal, ob Deine Datei schreibgeschützt ist.
Gruß: Bernd
Gruß: Bernd
Das deutsche PureBasic-Forum
https://www.purebasic.fr/german/
Code: Alles auswählen
EnableExplicit
Global tCreation , tLastAccess, tLastWrite
Global ReadFolderTime,WriteFolderTime
Define sFolder.s = "c:\temp"
Procedure.s GetTime()
Protected s.SYSTEMTIME
Protected t$
With s
t$=RSet(Str(\wDay) ,2,"0") +"."
t$+RSet(Str(\wMonth) ,2,"0") +"."
t$+RSet(Str(\wYear) ,4,"0") +" "
t$+RSet(Str(\wHour) ,2,"0") +":"
t$+RSet(Str(\wMinute) ,2,"0") +":"
t$+RSet(Str(\wSecond) ,2,"0")
EndWith
ProcedureReturn t$
EndProcedure
; ------ Datumswerte ermitteln
Procedure ReadFolderTime(sFolder.s)
; Datum/Zeitwert eines Ordners ermitteln
Protected fHandle.l
Protected ftCreation.FILETIME
Protected ftLastAccess.FILETIME
Protected ftLastWrite.FILETIME
Protected LocalFileTime.FILETIME
Protected LocalSystemTime.SYSTEMTIME
Protected ReadFolderTime = #False
; ggf. abschließenden Backslash hinzufügen
If Right(sFolder, 1) <> "\" : sFolder = sFolder + "\" : EndIf
; Verzeichnishandle ermitteln
fHandle = CreateFile_(sFolder, #GENERIC_READ|#GENERIC_WRITE, #FILE_SHARE_READ|#FILE_SHARE_WRITE, 0, #OPEN_EXISTING, #FILE_FLAG_BACKUP_SEMANTICS, 0)
If fHandle <> -1
; Zeitinformationen auslesen
If GetFileTime_(fHandle, ftCreation, ftLastAccess, ftLastWrite) <> 0
; Erstellungsdatum
FileTimeToLocalFileTime_( ftCreation, LocalFileTime)
FileTimeToSystemTime_( LocalFileTime, LocalSystemTime)
tCreation=ParseDate("%dd.%mm.%yyyy %hh:%ii:%ss",GetTime())
; Letzter Zugriff
FileTimeToLocalFileTime_( ftLastAccess, LocalFileTime)
FileTimeToSystemTime_( LocalFileTime, LocalSystemTime)
tLastAccess = ParseDate("%dd.%mm.%yyyy %hh:%ii:%ss",GetTime())
; Letzte Änderung
FileTimeToLocalFileTime_( ftLastWrite, LocalFileTime)
FileTimeToSystemTime_( LocalFileTime, LocalSystemTime)
tLastWrite =ParseDate("%dd.%mm.%yyyy %hh:%ii:%ss",GetTime())
ReadFolderTime = #True
EndIf
; Verzeichnishandle schließen
CloseHandle_( fHandle)
EndIf
ProcedureReturn ReadFolderTime
EndProcedure
; ------ Datumswerte ändern
Procedure WriteFolderTime(sFolder.s)
; Datum/Zeitwert eines Ordners ändern
Protected fHandle.l
Protected ftCreation.FILETIME
Protected ftLastAccess.FILETIME
Protected ftLastWrite.FILETIME
Protected LocalFileTime.FILETIME
Protected LocalSystemTime.SYSTEMTIME
Protected WriteFolderTime = #False
; ggf. abschließenden Backslash hinzufügen
If Right(sFolder, 1) <> "\" : sFolder = sFolder + "\" : EndIf
; Verzeichnishandle ermitteln
fHandle = CreateFile_(sFolder, #GENERIC_READ | #GENERIC_WRITE, #FILE_SHARE_READ | #FILE_SHARE_WRITE, 0, #OPEN_EXISTING, #FILE_FLAG_BACKUP_SEMANTICS, 0)
If fHandle <> -1
; Erstellungsdatum
With LocalSystemTime
\wDay = Day(tCreation)
;\wDayOfWeek = DayOfWeek(tCreation)
\wMonth = Month(tCreation)
\wYear = Year(tCreation)
\wHour = Hour(tCreation)
\wMinute = Minute(tCreation)
\wSecond = Second(tCreation)
EndWith
SystemTimeToFileTime_(LocalSystemTime, LocalFileTime)
LocalFileTimeToFileTime_(LocalFileTime, ftCreation)
; Letzter Zugriff
With LocalSystemTime
\wDay = Day(tLastAccess)
;\wDayOfWeek = Weekday(tLastAccess)
\wMonth = Month(tLastAccess)
\wYear = Year(tLastAccess)
\wHour = Hour(tLastAccess)
\wMinute = Minute(tLastAccess)
\wSecond = Second(tLastAccess)
EndWith
SystemTimeToFileTime_(LocalSystemTime, LocalFileTime)
LocalFileTimeToFileTime_(LocalFileTime, ftLastAccess)
; Letzte Änderung
With LocalSystemTime
\wDay = Day(tLastWrite)
;\wDayOfWeek = Weekday(tLastWrite)
\wMonth = Month(tLastWrite)
\wYear = Year(tLastWrite)
\wHour = Hour(tLastWrite)
\wMinute = Minute(tLastWrite)
\wSecond = Second(tLastWrite)
EndWith
SystemTimeToFileTime_(LocalSystemTime, LocalFileTime)
LocalFileTimeToFileTime_(LocalFileTime, ftLastWrite)
; Datumswerte neu setzen
If SetFileTime_(fHandle, ftCreation, ftLastAccess, ftLastWrite) <> 0
WriteFolderTime = #True
EndIf
; Verzeichnishandle schließen
CloseHandle_ (fHandle)
EndIf
ProcedureReturn WriteFolderTime
EndProcedure
; ------ Aufruf der Funktionen:
; Zeitangaben lesen
If ReadFolderTime(sFolder)
; Erstellungsdatum ändern
tCreation = ParseDate("%dd.%mm.%yyyy %hh:%ii:%ss","29.08.2002 17:35:41")
; Datum "Letzter Zugriff" ändern
tLastAccess = ParseDate("%dd.%mm.%yyyy %hh:%ii:%ss","29.08.2002 17:35:41")
; Datum "Letzter Änderung" ändern
tLastWrite = ParseDate("%dd.%mm.%yyyy %hh:%ii:%ss","30.03.2012 17:35:41")
; Zeitangaben setzen
WriteFolderTime(sFolder)
EndIf