Jump to content

VBS Copy folder to multiple locations specified in text file


Recommended Posts

Posted

Hi All.

 

I need to copy a folder (containing Files) into multiple locations that are specified in a txt file (a file location on each line)

 

I have below code to get started... It copies a folder to all sub folders, rather than selecting from text file - not sure if this helps in any way

 

Help very much appreciated

 

Ben

 

 

 

 

Set fso = CreateObject("Scripting.FileSystemObject")

 

set mainfolder=fso.GetFolder("C:\vbcopy\shorts\")

 

Set foldercollection = mainfolder.SubFolders

 

For Each folder In foldercollection

 

fso.copyfile "C:\vbcopy\Copyfile.txt", folder&"\Copyfile.txt", true

 

Next

Posted

Try this, all you need to add is the odd bit of code you already have :)

 

i have added a few comments to the code to help - or atleast try :D

 

Let me know how you get on

 

Mark

 

Set myFSO = CreateObject("Scripting.FileSystemObject")

filelocation = "Full PATH here" 'Enter the location of your txt file here

If myFSO.FileExists(filelocation) Then 'this checks if the file exists

Set logfile = myFSO.OpenTextFile(filelocation, 1) 'opens the text file for reading only

Do While Not logfile.AtEndOfStream 'initiates a loop and loops until the end of the file
  	strcontents = ""
strcontents = logfile.ReadLine 'reads a line into the variable

   If Not strcontents = "" then 'checks the line is not empty

            'DO YOUR WORK HERE

   End if	    
    
Loop

logfile.Close 'closes the file

end if

  • Thanks 1
Posted

With my thanks to sister_annex for their help:D, the following script now works like a dream, I have published it here to aid others if they need similar script.....

 

 

Set myFSO = CreateObject("Scripting.FileSystemObject")

filelocation = "c:\vbcopy\paths.txt" 'Enter the location of your txt file here

If myFSO.FileExists(filelocation) Then 'this checks if the file exists

Set logfile = myFSO.OpenTextFile(filelocation, 1) 'opens the text file for reading only

Do While Not logfile.AtEndOfStream 'initiates a loop and loops until the end of the file
  	strcontents = ""
strcontents = logfile.ReadLine 'reads a line into the variable

   If Not strcontents = "" then 'checks the line is not empty

            'DO YOUR WORK HERE

	Set fso = CreateObject("Scripting.FileSystemObject") 

	Set FSO =CreateObject("scripting.FileSystemObject")
    		fso.copyfolder "C:\vbcopy\Student Data files", strcontents&"\", true


   End if	    
    
Loop

logfile.Close 'closes the file

end if

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...