Solved

Script to copy select folders/files based on an external list in a text file

Posted on 2014-01-07
4
837 Views
Last Modified: 2014-01-07
I have a directory on a windows server that contains over 100,000 documents and I would like to copy some of these to a different drive but I need to preserve the folder structure as well.  I have a list of the folder/file names in a text file and would like a script to automate this process.  How would I do this?

For example, the directory has folders/files similar to this:

C:\Files\AAA\File1.doc
C:\Files\AAA\File2.doc
C:\Files\AAA\File3.doc
C:\Files\BBB\File1.doc
C:\Files\BBB\File2.doc
C:\Files\BBB\File3.doc
C:\Files\CCC\File1.doc
...


My text file might contain something like this:

C:\Files\AAA\File2.doc
C:\Files\BBB\File1.doc
C:\Files\CCC\File3.doc

So I would like my script to loop through the list in the text file and only copy those files while preserving the folder structure.  

So the new directory would be:

D:\Files\AAA\File2.doc
D:\Files\BBB\File1.doc
D:\Files\CCC\File3.doc



Thanks
0
Comment
Question by:mgcIT
  • 2
  • 2
4 Comments
 
LVL 17

Expert Comment

by:Kent Dyer
ID: 39763801
Does this have to be a VBScript?

If not, I would look into the use of ROBOCOPY/FORFILES to do this task.
 
ROBOCOPY is pretty comprehensive in the sense, you can copy whole trees, apply ACLS/etc.
0
 
LVL 18

Author Comment

by:mgcIT
ID: 39763831
no, does not have to be VBScript.  Can either of those only copy select files/folders based on a predetermined list?
0
 
LVL 17

Accepted Solution

by:
Kent Dyer earned 500 total points
ID: 39763871
FOR /F "delims=" %%A IN ('type filelist.txt') DO ROBOCOPY %%A D: /MIR

Open in new window


WHERE YOU WOULD HAVE filelist.txt setup as:
C:\Files\AAA\File1.doc
C:\Files\AAA\File2.doc
C:\Files\AAA\File3.doc
C:\Files\BBB\File1.doc
C:\Files\BBB\File2.doc
C:\Files\BBB\File3.doc
C:\Files\CCC\File1.doc

Open in new window


And would MIRROR or duplicate the structure on the D: drive.

Ref. - http://ss64.com/nt/robocopy.html or ROBOCOPY /?
0
 
LVL 18

Author Closing Comment

by:mgcIT
ID: 39763881
Thank you
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

685 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