1 1 1 1 1 1 1 1 1 1 Rating 5.00 (1 Vote)

Für 32Bit und 64Bit Office Versionen

Problemstellung:

Wie kann ich mit dem FileSystemObject (FSO) eine Datei kopieren? 

Public Function CopyFileFSO(strSourceFile As String, strTargetFile As String, _
                            Optional boolOverwrite As Boolean = True)
'*******************************************
'Name:      CopyFileFSO (Function)
'Purpose:   Datei kopieren
'Author:    Tommyk
'Date:      März 11, 2004, 04:15:02
'Inputs:    strSourceFile=Pfad und Name der Quelldatei, strTargetFile= Pfad und Name der Zieldatei
'           boolOverwrite= vorhandene Dateien werden überschrieben
'Output:
'*******************************************
On Error GoTo Err_Handler
   
If boolOverwrite = True Then
    oFSO.CopyFile strSourceFile, strTargetFile
Else
    oFSO.CopyFile strSourceFile, strTargetFile, False
End If
    
Err_Handler_Exit:
    Exit Function
Err_Handler:
    Dim strErrString As String
    strErrString = "Error Information..." & vbCrLf
    strErrString = strErrString & "Error#: " & Err.Number & vbCrLf
    strErrString = strErrString & "Description: " & Err.Description & vbCrLf
    MsgBox strErrString, vbCritical + vbOKOnly, "Error in Function: CopyFileFSO"
    Resume Err_Handler_Exit
End Function


Aufruf:

CopyFileFSO "H:\Test\Crypter.dll", "H:\Daten\Test\Crypter.dll"

würde die Datei "H:\Test\Crypter.dll" nach H:\Daten\Test\Crypter.dll kopieren, ist die Datei dort bereits
vorhanden wird sie überschrieben.

CopyFileFSO "H:\Test\Crypter.dll", "H:\Daten\Test\Crypter.dll", False

würde die Datei "H:\Test\Crypter.dll" nach "H:\Daten\Test\Crypter.dll" kopieren, ist die Datei dort bereits
vorhanden wird sie nicht überschrieben.

 

Ähnliche Artikel