copy files listed in table to another directory

  • Thread starter Thread starter niksto
  • Start date Start date
N

niksto

In an access 2k table named myfiles I have the full path and filename of
distinctive files;like d:\_aa\customer\1202.bmp in the field
logo (saved as text). I want access to copy these files to a new directory
d:\mycopy placing all in the
same directory (no subdirectory)

Any idea or examplecode?
 
niksto said:
In an access 2k table named myfiles I have the full path and filename
of distinctive files;like d:\_aa\customer\1202.bmp in the field
logo (saved as text). I want access to copy these files to a new
directory d:\mycopy placing all in the
same directory (no subdirectory)

Any idea or examplecode?

Use the VBA FileCopy statement. Here's a very simple example:

'----- start of example "air code" -----
Dim rs As DAO.Recordset
Dim strFileName As String
Dim strTargetFolder As String

strTargetFolder = "d:\mycopy\"

Set rs = CurrentDb.OpenRecordset("MyFiles")
With rs
Do Until .EOF
strFileName = Dir(!logo)
If Len(strFileName) = 0 Then
MsgBox "File '" & !logo & "' not found."
Else
FileCopy !logo, strTargetFolder & strFileName
End If
.MoveNext
Loop
.Close
End With
Set rs = Nothing
'----- end of code -----

However, can you be sure you won't have any name collisions? If not,
you'll have to check in the target folder first to see if the filename
you want to copy already exists. You can use the Dir() function for
that. If the file already exists, then you must decide what to do about
it.
 
Back
Top