Hallo.
Ich erhalte täglich einige PDF-Dateien per mail und möchte die vernünftig und einfach archivieren.
Bisher ändere ich den Dateinamen manuell, dies möchte ich aber vereinfachen.
Die Datei speichere ich in einen Sammelordner.
Dann möchte ich alle paar Tage ein VB-programm starten, welches mit in den Dateinamen das Datum der jeweiligen Datei schreibt.
Weiß jemand wie ich das Datum auslesen und formatieren kann?
Weiß jemand wie ich das Datum auslesen und formatieren kann?
ja, aber nicht erschrecken.
Option Explicit
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAborted As Boolean
hNameMaps As Long
sProgress As String
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Const GENERIC\_WRITE = &H40000000
Private Const OPEN\_EXISTING = 3
Private Const FILE\_SHARE\_READ = &H1
Private Const FILE\_SHARE\_WRITE = &H2
Private Const FO\_DELETE = &H3
Private Declare Function CreateFile Lib "kernel32" \_
Alias "CreateFileA" (ByVal lpFileName As String, \_
ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, \_
lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, \_
ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function GetFileTime Lib "kernel32" \_
(ByVal hFile As Long, lpCreationTime As FILETIME, \_
lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32" \_
(lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
Private Declare Function FileTimeToLocalFileTime Lib "kernel32" \_
(lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long
Private Declare Function CloseHandle Lib "kernel32" \_
(ByVal hObject As Long) As Long
Private Sub Command1\_Click()
Dim lngHandle As Long, SHDirOp As SHFILEOPSTRUCT, lngLong As Long
Dim Ft1 As FILETIME, Ft2 As FILETIME, Ft3 As FILETIME, FtC As FILETIME, SysTime As SYSTEMTIME
lngHandle = CreateFile("C:\Test.txt", GENERIC\_WRITE, FILE\_SHARE\_READ Or FILE\_SHARE\_WRITE, ByVal 0&, OPEN\_EXISTING, 0, 0)
GetFileTime lngHandle, Ft1, Ft2, Ft3
FileTimeToLocalFileTime Ft1, FtC
FileTimeToSystemTime FtC, SysTime
MsgBox "Datei erstellt am: " + CStr(SysTime.wDay) + "." + CStr(SysTime.wMonth) + "." + CStr(SysTime.wYear)
FileTimeToLocalFileTime Ft2, FtC
FileTimeToSystemTime FtC, SysTime
MsgBox "Letzter Zugriff am: " + CStr(SysTime.wDay) + "." + CStr(SysTime.wMonth) + "." + CStr(SysTime.wYear)
FileTimeToLocalFileTime Ft3, FtC
FileTimeToSystemTime FtC, SysTime
MsgBox "Letzter Schreibvorgang am: " + CStr(SysTime.wDay) + "." + CStr(SysTime.wMonth) + "." + CStr(SysTime.wYear)
CloseHandle lngHandle
End Sub
Trotz der Warnung habe ich mich erschrocken
Hallo Rainer,
soviel Aufwand um das Datum auszulesen und irgendwo einzufügen!?
Okay, wenn du was einfacheres wüßtest hättest du es geschrieben.
Ich wundere mich aber sehr über die Fähigkeiten von VB.
Lieben Gruß
Reinhard
soviel Aufwand um das Datum auszulesen und irgendwo
einzufügen!?
Okay, wenn du was einfacheres wüßtest hättest du es
geschrieben.
Nö. Es gibt IMO noch den Weg über FSO mit weniger Code, aber das ist so tränig langsam, daß ich mich nicht näher damit befasst habe. Das hier ist etwa 20 mal so schnell. Sobald es ein paar Dateien mehr werden, wird der Unterschied wesentlich.
Würde ich das brauchen, würde ich mir ein OCX daraus machen und dann bliebe im Code nur noch ‚ct = Creationtime(„C:\Test.txt“)‘ übrig.
Ich wundere mich aber sehr über die Fähigkeiten von VB.
Ich wundere mich bei VB über gar nichts mehr. Geht nicht gibt’s nicht! *fg*