We help IT Professionals succeed at work.
Get Started

VBScript to copy files from a share to a local drive

Last Modified: 2012-06-21
I'm trying to create a script to do the above, can someone give me some guidance on the best way to do it pls?

The code I have so far is below but doesn't work as I would expect:

set fso = CreateObject("Scripting.FileSystemObject")
sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
moveToDrive = "D:\"
set failures = fso.CreateTextFile(moveToDrive & "failures.txt")
Set objFolder = fso.GetFolder(sCurPath)

ShowSubFolders objFolder, fso

WScript.Echo "The operation has successfully completed."

Sub ShowSubFolders(objFolder, fso)
    On Error Resume Next
	fso.CopyFolder objFolder, moveToDrive
    Set colFiles = objFolder.Files
    For Each objFile In colFiles
			objFilePath = objFile.Path
			objFileName = objFile.Name
			strLen = len(objFilePath)
			moveToLocation = right(objFilePath, (strLen - 3))
			wscript.echo moveToDrive & moveToLocation
			fso.CopyFile objFile, "D:\Documents and Settings\t104ahe\Desktop\Copy script test\" & objFileName
			fso.CopyFile objFile, moveToDrive & moveToLocation
			If Err.number <> 0 Then 
				failures.WriteLine "Error copying " & objFile.Path
			End if
			On Error GoTo 0
  Set colFolders = objFolder.SubFolders
  For Each objSubFolder In colFolders
    ShowSubFolders objSubFolder, fso
  If Err.number <> 0 Then 
	failures.WriteLine "Error copying " & objFile.Path
  End if
  On Error GoTo 0
End Sub

Open in new window

Watch Question
IT Section Manager
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE