Solved: simple .vbs questiong

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

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

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?
 
Joined
Sep 4, 2003
Messages
4,912
the_oliver said:
Thanks. Very helpful. Is there some way that i can do it with out the message box?
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
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

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 807,865 other people just like you!

Latest posts

Members online

Top