D
Dic_nutana
Hi Guys
I'm trying to copy files from one folder to an archive folder on the same
drive. I'm using the code below which I thought may work, but I get an error
"Bad file name or number" on the "strFileName = "*.*"" part. I sure it’s the
wild card bit that’s giving the error.
So my question is how do I/can I, copy using wild cards and FileCopy or is
there a different command?
Both c:\test\ and c:\test2\ exist on the drive as do 2 test files
testfile.txt and testfile.pdf in C:\test\
I have tried several options but none seem to work, however it will work
copying just one file, specifying the file name instead of *.*. Can you help
please?
I'm using access 2003. Thanks in advance
Private Sub Command79_Click()
On Error GoTo Err_Command79_Click
Dim strFileName As String
Dim strSourcePath As String
Dim strTargetPath As String
Dim strSubPath As String
strSep = "\"
strSourcePath = "C:\test\"
strTargetPath = "C:\test2\"
strSubPath = Me.[works address1] & strSep
strFileName = strSubPath & "*.*"
‘Make the new directory to copy the files too
MkDir strTargetPath & strSubPath
‘Copy all the files over to new directory
Do While strFileName <> vbNullString
FileCopy strSourcePath & strFileName, strTargetPath & strFileName
Loop
MsgBox "Files Archived"
‘Next delete the original files and then the directory
Kill strSourcePath & strSep & Me.[works address1] & strSep & "*.*"
RmDir strSourcePath & strSep & Me.[works address1]
MsgBox "Original Folder and Files Deleted"
Exit_Command79_Click:
Exit Sub
Err_Command79_Click:
MsgBox Err.Description
End Sub
I'm trying to copy files from one folder to an archive folder on the same
drive. I'm using the code below which I thought may work, but I get an error
"Bad file name or number" on the "strFileName = "*.*"" part. I sure it’s the
wild card bit that’s giving the error.
So my question is how do I/can I, copy using wild cards and FileCopy or is
there a different command?
Both c:\test\ and c:\test2\ exist on the drive as do 2 test files
testfile.txt and testfile.pdf in C:\test\
I have tried several options but none seem to work, however it will work
copying just one file, specifying the file name instead of *.*. Can you help
please?
I'm using access 2003. Thanks in advance
Private Sub Command79_Click()
On Error GoTo Err_Command79_Click
Dim strFileName As String
Dim strSourcePath As String
Dim strTargetPath As String
Dim strSubPath As String
strSep = "\"
strSourcePath = "C:\test\"
strTargetPath = "C:\test2\"
strSubPath = Me.[works address1] & strSep
strFileName = strSubPath & "*.*"
‘Make the new directory to copy the files too
MkDir strTargetPath & strSubPath
‘Copy all the files over to new directory
Do While strFileName <> vbNullString
FileCopy strSourcePath & strFileName, strTargetPath & strFileName
Loop
MsgBox "Files Archived"
‘Next delete the original files and then the directory
Kill strSourcePath & strSep & Me.[works address1] & strSep & "*.*"
RmDir strSourcePath & strSep & Me.[works address1]
MsgBox "Original Folder and Files Deleted"
Exit_Command79_Click:
Exit Sub
Err_Command79_Click:
MsgBox Err.Description
End Sub