benIT Posted May 20, 2010 Posted May 20, 2010 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
sister_annex Posted May 20, 2010 Posted May 20, 2010 I Think you need to open the file and read it in to the script - can't remember off the top of my head how this works but i may be able to find an example Mark
sister_annex Posted May 20, 2010 Posted May 20, 2010 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 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 1
benIT Posted May 21, 2010 Author Posted May 21, 2010 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now