Jump to content

Recommended Posts

Posted

I need a vb script that will check to see if a folder is in the c:\program files, if it is then do nothing if not then copy the folder and its contents to the c:\program files of the pc from an area on the network.

 

I have a script that does this on one folder and one file but i want it to copy the contents of an whole folder?

 

Must be a VB as we ban .bat files.

Posted

' NewFolderEC.vbs
' Free example VBScript to create a folder with error-correcting Code.
' Author Guy Thomas [url]http://computerperformance.co.uk/[/url]
' Version 2.6 - May 2005
' ---------------------------------------------------------------'

Option Explicit
Dim objFSO, objFolder, objShell, strDirectory
strDirectory = "c:\program files\Directory to create"

' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Note If..Exists. Then, Else ... End If construction
If objFSO.FolderExists(strDirectory) Then
  Set objFolder = objFSO.GetFolder(strDirectory)
'folder allready exists
Else
  Set objFolder = objFSO.CreateFolder(strDirectory)
'Create Folder
End If

If err.number = vbEmpty then
  Set objShell = CreateObject("WScript.Shell")
Else WScript.echo "VBScript Error: " & err.number
End If

WScript.Quit

' End of Sample VBScript to create a folder with error-correcting Code

'Now add files to folder suing suitable code

 

Ben

Posted

SET G = oFS.GetFolder()
SET f = G.Files
   FOR EACH f1 in f
       oFS.CopyFile f1, ,TRUE
   NEXT

 

Should copy everything from the source folder to the destination.

 

Ben

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...