Seite 1 von 1

Probleme mit GetFileTime_()

Verfasst: 24.02.2005 15:45
von nco2k
hi folks,

irgendwie bekomme ich einfach kein richtiges ergebnis raus, es kommt immer "01.01.1601 00:00:00" raus. :?

Code: Alles auswählen

Procedure.s GetFileTime(File.s)
  If FileSize(File) => 0
    hFile.l = ReadFile(#PB_Any, File)
    If hFile
      GetFileTime_(hFile, @Create.FILETIME, @Access.FILETIME, @Write.FILETIME)
      FileTimeToSystemTime_(@Create, @SysTime.SYSTEMTIME)
      Stamp.s = ""
      If SysTime\wDay < 10
        Stamp+"0"+Str(SysTime\wDay)
      Else
        Stamp+Str(SysTime\wDay)
      EndIf
      Stamp+"."
      If SysTime\wMonth < 10
        Stamp+"0"+Str(SysTime\wMonth)
      Else
        Stamp+Str(SysTime\wMonth)
      EndIf
      Stamp+"."
      Stamp+Str(SysTime\wYear)
      Stamp+" "
      If SysTime\wHour < 10
        Stamp+"0"+Str(SysTime\wHour)
      Else
        Stamp+Str(SysTime\wHour)
      EndIf
      Stamp+":"
      If SysTime\wMinute < 10
        Stamp+"0"+Str(SysTime\wMinute)
      Else
        Stamp+Str(SysTime\wMinute)
      EndIf
      Stamp+":"
      If SysTime\wSecond < 10
        Stamp+"0"+Str(SysTime\wSecond)
      Else
        Stamp+Str(SysTime\wSecond)
      EndIf
      CloseFile(hFile)
      ProcedureReturn Stamp
    Else
      ProcedureReturn "failed"
    EndIf
  Else
    ProcedureReturn "missing"
  EndIf
EndProcedure

Debug GetFileTime("c:\test.txt")
getestet mit PB3.93b3 auf WinXP Pro Sp2.

hat jemand eine idee, woran es liegen könnte oder was ich falsch mache?! :(

c ya,
nco2k

Verfasst: 24.02.2005 18:36
von Robert
@nco2k

Problem ist das #PB-Any bei ReadFile. Ist möglicherweise ein Bug. Mit hFile.l = ReadFile(0, File) und CloseFile(0) funktioniert dein Programm.

Hier ist noch ein Code-Schnipsel mit ner Aufbereitungsroutine von NicktheQuick. Ist irgendwie eleganter und wiederverwendbar.

Code: Alles auswählen

Procedure.s StrEx(Value.l, Length.l)
  Protected StrEx.s
  StrEx = RSet(Str(Value), Length, "0")
  ProcedureReturn StrEx
EndProcedure

Procedure.s GetDateOfSystemTime(*SystemTime.SYSTEMTIME)
  Protected Date.s
  Date = StrEx(*SystemTime\wDay, 2) + "." + StrEx(*SystemTime\wMonth, 2) + "." + StrEx(*SystemTime\wYear, 4)
  ProcedureReturn Date
EndProcedure

Procedure.s GetTimeOfSystemTime(*SystemTime.SYSTEMTIME)
  Protected time.s
  time = StrEx(*SystemTime\wHour, 2) + ":" + StrEx(*SystemTime\wMinute, 2) + ":" + StrEx(*SystemTime\wSecond, 2)
  ProcedureReturn time
EndProcedure

Procedure.s GetStringOfSystemTime(*SystemTime.SYSTEMTIME)
  Protected String.s
  String = GetDateOfSystemTime(*SystemTime) + " " + GetTimeOfSystemTime(*SystemTime)
  ProcedureReturn String
EndProcedure

Procedure.s GetFileTime(File.s)
  If FileSize(File) => 0
    hFile.l = ReadFile(0, File)
    If hFile
      GetFileTime_(hFile, @Create.FILETIME, @Access.FILETIME, @WRITE.FILETIME)
      FileTimeToSystemTime_(@Create, @SystemTime.SYSTEMTIME)
      Stamp.s = GetStringOfSystemTime(@SystemTime)
      CloseFile(0)
      ProcedureReturn Stamp
    Else
      ProcedureReturn "failed"
    EndIf
  Else
    ProcedureReturn "missing"
  EndIf
EndProcedure

Debug GetFileTime("c:\test.txt")
Gruß Robert

Verfasst: 24.02.2005 18:49
von MVXA
Das ist kein Bug sondern einfach nur eine PB interne Zahl und nicht der Handle der IP. Den Handle bekommste so : OpenFile(0, "test.txt") so bekommste den Handle. Geht aber auch mit UseFile(<Rückgabe von OpenFile mit #PB_An>)

Verfasst: 24.02.2005 19:38
von nco2k
hätte nie gedacht, dass es an #PB_Any liegen könnte. :?

c ya,
nco2k

Verfasst: 24.02.2005 19:46
von MVXA
kannst des auch noch mit #PB_Any verwenden. Nur um den echten handle zu bekommen musste dir was anderes ausdenken. Hab es so gelöst:

Code: Alles auswählen

    hFile = OpenFile(#PB_Any, strFileName)
    
    GetFileTime_(UseFile(hFile), @Create, @Access, @Write)
    FileTimeToSystemTime_(@Create, @SysTime)
    CloseFile(hFile)

Verfasst: 24.02.2005 19:57
von ts-soft
Problem ist das #PB-Any bei ReadFile. Ist möglicherweise ein Bug.
Bei Benutzung von #PB_Any wird nicht das Windows-Übliche-Handle, sondern ein PB-Internes zurückgegeben. Ist also kein Bug sondern etwas, was man beachten sollte bei der Verwendung von #PB_Any

Verfasst: 24.02.2005 20:04
von nco2k
@MVXA & @ts-soft
ahh jetzt klingelts... :lol:

c ya,
nco2k

Verfasst: 24.02.2005 20:06
von Robert
@MVXA

Dein Lösungsvorschlag geht natürlich auch mit ReadFile. Ein Schreibzugriff wird ja nicht benötigt.

Code: Alles auswählen

hFile = ReadFile(#PB_Any, strFileName)
   
GetFileTime_(UseFile(hFile), @Create, @Access, @Write)
FileTimeToSystemTime_(@Create, @SysTime)
CloseFile(hFile)