Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy files from list ... part 2

Status
Not open for further replies.
thread329-1499715

All, I would like to thank you for posting the mentioned thread. Since I used part of the code to resolve my issue ... I figured I would post it here. Please note: I am an old C programmer ... so it may not be pretty ... but it works like a champ.

Option Explicit

Dim oFSO 'Variable for creating the FileSystemObject.
Dim sFile 'Variable for the text document with the list of files to be copied.
Dim oFile 'Variable for opening text document for reading.
Dim sText 'Vartiable for reading lines of the text file.
Dim strFilePath 'Variable for establishing folder and file paths.
Dim strSource 'Variable for establishing the Source Folder.
Dim strDestination 'Variable for establishing the Destination Folder.

Const ForReading = 1, ForWriting = 2, ForAppending = 8 'Constants used for opening text document.

'Set variables for text file location, source and destination.
sFile="<INSERT ABSOLUTE FILE PATH HERE>"
strSource="<INSERT ABSOLUTE FILE PATH HERE>"
strDestination="<INSERT ABSOLUTE FILE PATH HERE>"

'Set the read of the input file and prompt for locations.
set oFSO=CreateObject("Scripting.FileSystemObject")

'Open the file for reading and get the names of the files to be copied, and execute copy to new location.
If oFSO.FileExists(sFile) Then
Set oFile = oFSO.OpenTextFile(sFile, ForReading)
Do While Not oFile.AtEndOfStream
sText = oFile.ReadLine
If (Trim(sText) <> "") And oFSO.FileExists(strSource & "\" & sText) Then
oFSO.CopyFile strSource & "\" & sText, strDestination,True
Else
WScript.Echo "Couldn't find " & strSource & "\" & sText
End If
Loop
oFile.Close
Else
WScript.Echo "The file was not there."
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top