Solved

VBS reference .txt file to copy files

Posted on 2009-07-14
5
598 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

830 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