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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy files and folders of directory to another folder 1

Status
Not open for further replies.

esilva002

IS-IT--Management
May 5, 2010
15
US
I have a DailyBackup.vbs file that selects two drives and then copies the contents to their own folder for backup purposes. It looks like this:

Option Explicit

Dim FSO, StrDate, StrMonth, StrDay, StrYear, StrBackupFolder1, StrBackupFolder2, CopyFolder1, CopyFolder2, PasteFolder1, PasteFolder2

Const OverWriteFiles = True

Set FSO = WScript.CreateObject("Scripting.FileSystemObject")

StrDate = Date()

StrMonth = DatePart("m", StrDate)

StrDay = DatePart("d", StrDate)

StrYear = DatePart("yyyy", StrDate)

StrBackupFolder1 = "I:\Accounting\Backup" & StrMonth & "_" & StrDay & "_" & StrYear

StrBackupFolder2 = "I:\WorkArea\Backup" & StrMonth & "_" & StrDay & "_" & StrYear

If FSO.FolderExists(StrBackupFolder1) Then
'wscript.exit
Else
FSO.CreateFolder(StrBackupFolder1)
wscript.sleep (5 * 1000)
End If

If FSO.FolderExists(StrBackupFolder2) Then
'wscript.exit
Else
FSO.CreateFolder(StrBackupFolder2)
wscript.sleep (5 * 1000)
End If

CopyFolder1 = "D:\"

CopyFolder2 = "H:\"

PasteFolder1 = StrBackupFolder1

PasteFolder2 = StrBackupFolder2

FSO.CopyFolder CopyFolder1 , PasteFolder1 , OverWriteFiles

FSO.CopyFolder CopyFolder2 , PasteFolder2 , OverWriteFiles

I have this running for another company and it works fine. although I am not copying the entire drive in the other one like I am in this one. Would the fact that I am copying an entire drive give me problems?
 
The Error happens on line
"FSO.CopyFolder CopyFolder1 , PasteFolder1 , OverWriteFiles"
and most likely on the next line too
 
The Error happens
Which error ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Give this a go

Option Explicit

Dim FSO, StrDate, StrMonth, StrDay, StrYear, StrBackupFolder1, StrBackupFolder2, CopyFolder1, CopyFolder2, PasteFolder1, PasteFolder2
Const OverWriteFiles = True

Set FSO = WScript.CreateObject("Scripting.FileSystemObject")

StrDate = Date()
StrMonth = DatePart("m", StrDate)
StrDay = DatePart("d", StrDate)
StrYear = DatePart("yyyy", StrDate)
StrBackupFolder1 = "I:\Accounting\Backup" & StrMonth & "_" & StrDay & "_" & StrYear & "\"
StrBackupFolder2 = "I:\WorkArea\Backup" & StrMonth & "_" & StrDay & "_" & StrYear & "\"

'Source Files
CopyFolder1 = "Z:\*"
CopyFolder2 = "H:\*"

'Destination Folder
PasteFolder1 = StrBackupFolder1
PasteFolder2 = StrBackupFolder2

'Create Folder If not exist
If FSO.FolderExists(StrBackupFolder1) Then
'wscript.exit
Else
FSO.CreateFolder(StrBackupFolder1)
wscript.sleep 1000
End If

If FSO.FolderExists(StrBackupFolder2) Then
'wscript.exit
Else
FSO.CreateFolder(StrBackupFolder2)
wscript.sleep 1000
End If

'Copy all Directories From source to destination
FSO.CopyFolder CopyFolder1 , PasteFolder1 , OverWriteFiles
FSO.CopyFolder CopyFolder2 , PasteFolder2 , OverWriteFiles



NOTE: Your StrBackupFolder1 = "I:\Accounting\ will need to exist in order for your script to work. Here is a sub to do that if needed.

'Create the folders if they don't exist. Create Subfolders based on SmartCreateFolder

SmartCreateFolder(WshEnv("%SystemDrive%") & "\Accounting\Backup" )

Sub SmartCreateFolder(strFolder)
Dim oFSO
Set oFSO = CreateObject("Scripting.FileSystemObject")
If oFSO.FolderExists(strFolder) Then
Exit Sub
Else
SmartCreateFolder(oFSO.GetParentFolderName(strFolder))
End If
oFSO.CreateFolder(strFolder)
Set oFSO = Nothing
End Sub

MCITP:EA/SA, MCSE, MCSA, MCDBA, MCTS, MCP+I, MCP
 
why would anyone want to wait any amount of time after a .CreateFolder method call?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top