+ Post New Thread
Results 1 to 4 of 4
Scripts Thread, VBS Copy folder to multiple locations specified in text file in Coding and Web Development; Hi All. I need to copy a folder (containing Files) into multiple locations that are specified in a txt file ...
  1. #1

    Join Date
    Feb 2007
    Posts
    82
    Thank Post
    21
    Thanked 3 Times in 3 Posts
    Rep Power
    16

    VBS Copy folder to multiple locations specified in text file

    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

  2. #2
    sister_annex's Avatar
    Join Date
    Jan 2009
    Location
    Wolverhampton
    Posts
    594
    Thank Post
    99
    Thanked 136 Times in 120 Posts
    Rep Power
    49
    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

  3. #3
    sister_annex's Avatar
    Join Date
    Jan 2009
    Location
    Wolverhampton
    Posts
    594
    Thank Post
    99
    Thanked 136 Times in 120 Posts
    Rep Power
    49

    This

    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

    Code:
    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

  4. Thanks to sister_annex from:

    benIT (21st May 2010)

  5. #4

    Join Date
    Feb 2007
    Posts
    82
    Thank Post
    21
    Thanked 3 Times in 3 Posts
    Rep Power
    16

    Final Script to copy a directory to multiple locations in a text file...

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


    Code:
    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

SHARE:
+ Post New Thread

Similar Threads

  1. List computers in Domain in a text file with vbs
    By FatBoy in forum How do you do....it?
    Replies: 5
    Last Post: 15th February 2010, 12:29 PM
  2. Replies: 3
    Last Post: 5th May 2009, 03:00 PM
  3. Copy file across variable folder name
    By SimpleSi in forum *nix
    Replies: 11
    Last Post: 10th March 2009, 06:15 PM
  4. VBS Script to copy a folder
    By FN-GM in forum Scripts
    Replies: 2
    Last Post: 23rd February 2008, 01:08 PM
  5. Replies: 4
    Last Post: 7th March 2007, 03:37 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •