1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: simple .vbs questiong

Discussion in 'Software Development' started by the_oliver, Jan 21, 2007.

Thread Status:
Not open for further replies.
Advertisement
  1. the_oliver

    the_oliver Thread Starter

    Joined:
    Jan 21, 2007
    Messages:
    5
    Hello,

    Need some help with a .vbs scrip im writing please. (not visual basic). Have a few problems i need to overcome.

    Firstly i need a way for the script to read in lines one by one from a .txt file, so they can be used as variables, passed to a function. So it would do something like FOR 'all lines, one at a time' DO 'the following' UNTILL 'end of file'.


    The next is to find a way to copy a directory and its subdirectys. I can do it with a single file by using the folowing but need to be able to cope with directorys:

    Code:
    set fs =wscript.CreateObject("Scripting.FileSystemObject"
    set f1 = fs.GetFile( source )
    fs.GetFile( target ).Copy target,True
    

    Sure its not hard, just have no idea where to start! Thanks.
     
  2. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    Here is some code to loop through the text file line by line. The script will loop through each line and set its value equal to the variable vLineText where it will be echoed on the screen in the form of a messagebox. Just change the code to reflect what you would like to do with the variable.

    Code:
    Const ForReading = 1
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile("C:\Test.txt", ForReading)
    
    Do Until objFile.AtEndOfStream
        vLineText = objFile.ReadLine
    	Wscript.Echo vLineText
    Loop
    
    objFile.Close
    To copy a directory you may use

    Code:
     Dim objFSO
     Dim vDestination
     Dim vSource
    
    vSource = "C:\TEST"     
    vDestination = "C:\TEST2"
    
         set objFSO = CreateObject("scripting.FileSystemObject")
    
         Call objFSO.CopyFolder(vSource, vDestination)
    
         set objFSO = Nothing
    Regards,
    Rollin
     
  3. the_oliver

    the_oliver Thread Starter

    Joined:
    Jan 21, 2007
    Messages:
    5
    Thanks. Very helpful. Is there some way that i can do it with out the message box?
     
  4. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    Just remove the line below. It was included only for testing purpose.

    Code:
    Wscript.Echo vLineText
    If this solves your problem please mark the thread as solved using the thread tools at the top.

    Regards,
    Rollin
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Similar Threads - Solved simple questiong
  1. Pedro14
    Replies:
    0
    Views:
    225
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/537111

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice