Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy - delete files

Status
Not open for further replies.

perto

IS-IT--Management
Sep 21, 2000
10
0
0
BE
Can anybody give me the code to copy all the files from a directory to a backup directory and then delete all the files in the first directory

Thnx
 
Copy everything below between the double lines, into a new module, changing the red paths appropriately. The FROMPATH is the folder in which the files currently reside, and the TOPATH is where you want them copied to. That's it.

Now to run it, you can either go to the debug window (ctrl + G) and type the following, or put it on the click event of a button:

Call BackupFiles()

====================
Public Const FROMPATH As String = "C:\TestFolder\"
Public Const TOPATH As String = "C:\TestFolder\BackupFolder\"

-------------------
Public Sub BackupFiles()
On Error GoTo Err_Import
Dim strFile As String, strOldFile As String, strNewFile As String

strFile = Dir(FROMPATH & "*.*")

DoCmd.Hourglass True
Do While strFile <> &quot;&quot;
strOldFile = FROMPATH & strFile
strNewFile = TOPATH & strFile
FileCopy strOldFile, strNewFile
Kill strOldFile
strFile = Dir
Loop

Exit_Import:
DoCmd.Hourglass False
MsgBox &quot;Process Complete&quot;
Exit Sub

Err_Import:
MsgBox Err & Err.Description, , &quot;Error in Import&quot;
Resume Exit_Import
End Sub
====================
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top