Solved

advanced file copy vbs script required

Posted on 2011-02-15
4
546 Views
Last Modified: 2012-05-11
I need a vbs sript to copy all the files in folder A to folder B

Error control:-
*  If the destination folder (B) does not exist, do not attempt copy or show an error.
*  If the destination folder does exist, but the target files are already there, do not copy the files or show an error.

Thanks!
0
Comment
Question by:browndobe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 34895621
Hi,this should do what you are asking.

Regards,

Rob.
Set objFSO = CreateObject("Scripting.FileSystemObject")
strSource = "C:\Temp\Source"
strDestination = "C:\Temp\Destination"

If objFSO.FolderExists(strSource) = True Then
	If objFSO.FolderExists(strDestination) = True Then
		If Right(strDestination, 1) <> "\" Then strDestination = strDestination & "\"
		If objFSO.FileExists(strDestination & objFile.Name) = False Then objFSO.CopyFile objFile.Path, strDestination, False
	End If
End If

Open in new window

0
 

Author Comment

by:browndobe
ID: 34896330
greetings RobSampson,
                      I get an error:-
Error-01.jpg
0
 
LVL 5

Accepted Solution

by:
Tompa99 earned 50 total points
ID: 34897145
Hi,

It should look something like this to loop true the files.

Regards Tompa


Dim objFso
Dim strSource
Dim strDestination
Set objFso = WScript.CreateObject("Scripting.FileSystemObject")
strSource = "C:\Temp\Source"
strDestination = "C:\Temp\Destination"

if objFso.FolderExists(strSource) = true then
	
	if objFso.FolderExists(strDestination) = true then
		set objFolder = objFso.GetFolder(strSource)
		Set objFiles = objFolder.Files
		
		for each objFile in objFiles
		
			If Right(strDestination, 1) <> "\" Then strDestination = strDestination & "\"
			If objFso.FileExists(strDestination & objFile.Name) = False Then objFSO.CopyFile objFile.Path, strDestination, False
		
		next
	end if

end if

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 34900797
Oh, I forgot the Files loop...oh well...

Rob.
Set objFSO = CreateObject("Scripting.FileSystemObject")
strSource = "C:\Temp\Source"
strDestination = "C:\Temp\Destination"

If objFSO.FolderExists(strSource) = True Then
	If objFSO.FolderExists(strDestination) = True Then
		If Right(strDestination, 1) <> "\" Then strDestination = strDestination & "\"
		For Each objFile In objFSO.GetFolder(strSource).Files
			If objFSO.FileExists(strDestination & objFile.Name) = False Then objFSO.CopyFile objFile.Path, strDestination, False
		Next
	End If
End If

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question