Solved

VBS reference .txt file to copy files

Posted on 2009-07-14
5
599 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

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…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

734 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