thanks Trevor and rkc...
Kill C:\BackupDir\*.* seems easy enough, but how about comparing the files
and copying only those that have changed ?
Here's a first crack at it...
Public Sub sync loops through each record in the recordset, calling Public
Function HasFileAttrib which looks for the current record (from sync) in the
specified BackUp directory, and then gets the attributes of that file, if
found, and compares the attributes of the found file to the attributes of
the current record - if the attributes (e.g. modification time) are
different, then copy (overwrite) to Backup directory.
I know this code need a lot of work... any suggestions welcome!
Option Compare Database
Option Explicit
Type WIN32_FIND_DATA
lngFileAttributes As Long ' File attributes
ftCreationTime As FILETIME ' Creation time
ftLastAccessTime As FILETIME ' Last access time
ftLastWriteTime As FILETIME ' Last modified time
lngFileSizeHigh As Long ' Size (high word)
lngFileSizeLow As Long ' Size (low word)
lngReserved0 As Long ' reserved
lngReserved1 As Long ' reserved
strFilename As String * MAX_PATH ' File name
strAlternate As String * 14 ' 8.3 name
End Type
Private Declare Function FindFirstFile Lib "kernel32" _
Alias "FindFirstFileA" (ByVal lpFileName As String, _
lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" _
Alias "FindNextFileA" (ByVal hFindFile As Long, _
lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32" _
(ByVal hFindFile As Long) As Long
Public Sub sync()
Dim lngErrNum As Long
Dim varHlk As Variant
Dim strDt As String
Dim j As String
Dim strDoc As String
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("SELECT Document FROM tblDocuments
WHERE Document Is Not Null")
rst.MoveFirst
Do Until rst.EOF
DoEvents
varHlk = rst!Document
Debug.Print "varHlk = " & varHlk
strDt = HyperlinkPart(varHlk, 0)
Debug.Print "strDt = " & strDt
j = (InStr(1, varHlk, "#", 1)) + 7
strDoc = Right(varHlk, Len(varHlk) - j)
Debug.Print "strDoc = " & strDoc
modCompare.HasFileAttrib (strDoc)
rst.MoveNext
Loop
End Sub
Public Function HasFileAttrib(ByVal strDoc As String, _
Optional ByVal enmFlags As VbFileAttribute) As Boolean
Dim lngErrNum As Long
'Find file that matches strDoc in C:\Test
'GetAttr from matching strDoc and put in array?
'Compare Attr's between two files, return boolean if match
GetAttr strDoc
lngErrNum = Err
If lngErrNum > 0 Then
HasFileAttrib = False
Exit Function
End If
'define enmFlags by other file ?
If ((GetAttr(strDoc) And enmFlags) = enmFlags) Then
HasFileAttrib = True
Else
HasFileAttrib = False
End If
End Function
"deko" <dj****@hotmail.com> wrote in message
news:ST*****************@newssvr25.news.prodigy.co m...
Is there a quick and dirty way to delete all files in a given directory?
perhaps something like this:
Set objFile = CreateObject("Scripting.FileSystemObject")
objFile.DeleteFile "all files in C:\Temp" 'how to specify directory?
Do I need to use the Windows API?
Private Declare Function FindFirstFile Lib "kernel32 Alias
"FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As
WIN32_FIND_DATA) As Long
What I'm trying to do is maintain a backup directory of documents that are
hyperlinked to various records in my Access 2003 mdb. All the hyperlinks
are stored in a table, so it's just a matter of using FileCopy to copy the
documents to the backup directory. But first I want to purge the backup
directory of any existing files... how to get a list of files in the
directory?
Thanks in advance...