FileCopy Problem

cable

Access For My Sins
Local time
Today, 12:56
Joined
Mar 11, 2002
Messages
226
I've found an interesting problem:

FileCopy doesn't seem to want to copy 0 byte files, it reports a file not found.

Which would be ok and understandable, cept that explorer lists the files! :confused:

So does an empty file exist or not? is 0 something or nothing?
slightly inconsistant behaviour from microsoft here! :D
 
cable said:
FileCopy doesn't seem to want to copy 0 byte files, it reports a file not found.
I just tested this with Access 97 and it works fine for a 0 byte text tile. The text file does not contain any data.
Code:
FileCopy ("C:\Temp\TEST.txt"), ("C:\Temp\TEST1.txt")

This is what I use to copy all files from one directory to another...
Code:
Private Sub bCopyDirectoryFiles_Click()
On Error GoTo Err_bCopyDirectoryFiles_Click

'Your db must have a reference set to the "Microsoft Scripting Runtime"!
'From a module, click Tools/Reference then select "Microsoft Scripting Runtime".
'The scripting file is located @ C:\Windows\System32\scrrun.dll

    Dim fso As Scripting.FileSystemObject
    Dim sSourceDir As String, sDestinationDir As String
    
    Set fso = New Scripting.FileSystemObject
    
    sSourceDir = "C:\Temp\*.*"
    sDestinationDir = "C:\Temp\Test" 'No ending back slash for the final directory!
    
    fso.CopyFile sSourceDir, sDestinationDir, True

    MsgBox "Files copied"

Exit_bCopyDirectoryFiles_Click:
    Exit Sub

Err_bCopyDirectoryFiles_Click:
    If Err = 53 Then 'File not found
        Beep
        MsgBox "No files found in the source directory.", vbInformation
        Exit Sub
    ElseIf Err = 76 Then 'Path not found
        Beep
        MsgBox "The destination directory does not already exist.", vbInformation
        Exit Sub
    Else
        MsgBox Err.Number & " - " & Err.Description
        Resume Exit_bCopyDirectoryFiles_Click
    End If

End Sub
HTH
 

Users who are viewing this thread

Back
Top Bottom