Solved

VBS reference .txt file to copy files

Posted on 2009-07-14
5
595 Views
Last Modified: 2012-08-13
Hi Experts
I am looking to schedule a script that can reference a .txt file with a list of files & locations then copy them to a backup location.
Can this be done in VBS as new to scripting and really don't know where to start!

thanks



0
Comment
Question by:Ninjaguy900
  • 3
  • 2
5 Comments
 
LVL 28

Expert Comment

by:Bill Bach
ID: 24852993
Yes.  Define a File System Object:
   Public fso
   set fso = CreateObject("Scripting.FileSystemObject")

Read the file list in from the text file, then use the simple command:
    fso.CopyFile fso.BuildPath(OriginalDir,FileName), fso.BuildPath(BackupDir,FileName), True

Obviously, you need to define the variables:
OriginalDir: The original directory (which you can read from the text file)
BackupDir: The location for the backups
FileName: The file name to copy

The code for reading the files wiull vary depending on the format of your text file, of course, so I don't have sample code for that.
0
 
LVL 28

Expert Comment

by:Bill Bach
ID: 24853039
Something like this might work, if your source list is a simple list of filenames with full paths:

set Cfg = fso.OpenTextFile(ConfigFile)
do while not Cfg.AtEndOfStream
    str = RTrim(Cfg.ReadLine)
    fso.CopyFile str, fso.BuildPath(BackupDir,fso.GetFileName(str)), True
loop
0
 

Author Comment

by:Ninjaguy900
ID: 24857814
Many thanks
it's a start, but I'm still having trouble with the code to access the file

for example
If the ref file is c:\backups\ref_file.txt

looks like this
C:\GA\report\New Text Document.txt
C:\GA\report\New Text Document (2).txt
C:\GA\report\New Text Document (3).txt

how can i copy the file listed to a alternative location??

thanks
0
 
LVL 28

Accepted Solution

by:
Bill Bach earned 250 total points
ID: 24859548
You need to put in your own values into the script:

Public fso
set fso = CreateObject("Scripting.FileSystemObject")
set Cfg = fso.OpenTextFile("c:\backups\ref_file.txt")
do while not Cfg.AtEndOfStream
    str = RTrim(Cfg.ReadLine)
    fso.CopyFile str, fso.BuildPath("C:\alternativelocation",fso.GetFileName(str)), True
loop
0
 

Author Comment

by:Ninjaguy900
ID: 24859734
Thanks
spelling error on my part ! doh!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now