Question

so I have a few excel sheets that contain directories all stemming from a single root directory. Is there anyway to have robocopy (or similar program) read the excel sheet as input to only copy over the selected files?

This is the format of the spreadsheets:

NMMC c6 31b5ac6c-1377-4a86-90a0-73c6335907e3.IMG
NMMC 2e 1da3d2ec-526f-479a-9c09-90cb2cfad0b6.IMG
NMMC 8a f77168ad-2f35-490c-a2a8-25e9fa4ac0ea.IMG
NMMC 2f fc2162f8-7548-4921-b722-5899cbe54641.IMG
NMMC fc 1fe09fcd-3861-4de8-8bfd-4510ffa8f29c.IMG
hcri001 1b  243161b4-eef0-4d5c-9e42-dcea6772afdd.IMG
hcri001 a7  7e60ba72-fb8f-4d65-ae34-92b034c10e2e.IMG
hcri001 84  7934584f-7bc8-4450-bf6d-da58ac2ebb1a.IMG
hcri001 1a  cda461ab-fe9d-4b4f-87bf-43dab9dd8644.IMG
hcri001 2b  4f2c02b6-31c6-4d8b-975e-591778bcdfef.IMG
ICPS    8a  2aca38a8-4133-4972-a03f-8c3c15654df3.IMG
ICPS    89  8338f897-76c0-4f6f-9ae5-3b4c7e8a302c.IMG
ICPS    30  d9dba300-6c14-4484-a147-bccb9dd15aa3.IMG

I would like to copy these files to another filesystem with the same structure (For Example, if the image originates from C:\Apps\Test\Site\NMMC\c6\31b5ac6c-1377-4a86-90a0-73c6335907e3.IMG then I need it to copy to Z:\Apps\FileSystem\NMMC\c6\31b5ac6c-1377-4a86-90a0-73c6335907e3.IMG

Is this possible to do?

Thanks

Edited to clear up confusion

Was it helpful?

Solution 4

Ok, I think I pretty much have it. Here's the command prompt script that I'm running:

for /f "delims=, tokens=1,2,3" %i in ( D:\foo.csv ) do xcopy /i /y "Z:\%i\%j\%k" "D:\%i\%j\%k"

This is doing exactly what I want, however for each file it tries to copy a prompt appears asking me if it's a file or a directory. Is there anyway to tell xcopy that they're ALL files? I thought that's what /i did, but that doesn't seem to suppress the prompts.

OTHER TIPS

If you want to avoid writing Office Interop code my suggestion would be to do the following:

First, in Excel save your data as a CSV file to the path c:\temp\foo.csv. This will create a datafile that looks like the following:

NMMC,2e,1da3d2ec-526f-479a-9c09-90cb2cfad0b6.IMG
NMMC,8a,f77168ad-2f35-490c-a2a8-25e9fa4ac0ea.IMG
NMMC,2f,fc2162f8-7548-4921-b722-5899cbe54641.IMG
NMMC,fc,1fe09fcd-3861-4de8-8bfd-4510ffa8f29c.IMG

Next, open a command prompt and write the following command:

for /f "delims=, tokens=3" %i in ( c:\temp\foo.csv ) do echo %i

This will output all the file names (and just the file names). Once you are happy this is working then change the "echo %i" to be whatever xcopy command you want.

Create a batch file or shell script using a text editor. For example, you can find/replace so that the bat file contains something like this:

copy c:\31b5ac6c-1377-4a86-90a0-73c6335907e3.IMG
copy c:\1da3d2ec-526f-479a-9c09-90cb2cfad0b6.IMG
copy c:\f77168ad-2f35-490c-a2a8-25e9fa4ac0ea.IMG
copy c:\fc2162f8-7548-4921-b722-5899cbe54641.IMG
copy c:\1fe09fcd-3861-4de8-8bfd-4510ffa8f29c.IMG

You could try to use PowerShell's COM Automation to read the Excel file and feed the lines into copy, xcopy or robocopy.

I can't give an example on how this would be done in practise, my powershell-fu is not strong enough. Google might be your friend there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top