Batch file query for copying files

Ant555
Ant555 Posts: 1,591 Forumite
Part of the Furniture 1,000 Posts Photogenic Name Dropper
I have an excel file containing the names of 2000+ files such as file1.txt, file44.pdf, file888.xls

All of these files live in a single directory on an old Windows machine along with many thousands of other files.

I'd like to copy all of the files named in the excel document to a different directory.

copy d:\files\file1.txt e:\newcopy will work but I don't want to have to do that 2300 times.

Can anyone help with the syntax of a batch file or dos script that can lookup the name in a file (currently excel but can export to any format required) and copy it to a different location.

Many thanks in advance.

Comments

  • closed
    closed Posts: 10,886 Forumite
    As it's in excel, add a the copy commands in another column, export to txt/bat and run

    or use

    for
    !!
    > . !!!! ----> .
  • victor2
    victor2 Posts: 8,055 Ambassador
    Part of the Furniture 1,000 Posts Name Dropper
    If the list of files are in subsequent rows in Excel, just add a column to the right of each with a formula in the format of ="copy "&A1&" destination", where the copy source is included in the first quoted bit and the destination in the second.
    Copy that as values to a new sheet and save it as a txt file, rename it to .bat and there's your batch file.

    You can dump the list as a text file and have a batch file import each item into a command, but that's probably OTT for a one-off operation.

    I’m a Forum Ambassador and I support the Forum Team on the In My Home MoneySaving, Energy and Techie Stuff boards. If you need any help on these boards, do let me know. Please note that Ambassadors are not moderators. Any posts you spot in breach of the Forum Rules should be reported via the report button, or by emailing forumteam@moneysavingexpert.com. 

    All views are my own and not the official line of MoneySavingExpert.

  • billett05
    billett05 Posts: 24 Forumite
    You want to use a loop. Save your txt file as a CSV and replace the filename and end location foldername in the below (%%A is column A in excel):

    paste the below into notepad and rename to something like build.cmd, ensure your csv is in the same folder


    FOR /F "tokens=1,2,3,4,5,6,* delims=," %%A IN (filename.csv) DO (
    echo copy %%A c:\foldername >> move.cmd
    )
    call move.cmd
  • Ant555
    Ant555 Posts: 1,591 Forumite
    Part of the Furniture 1,000 Posts Photogenic Name Dropper
    Woohoo!

    Done and dusted!

    Many thanks to everyone -

    I used the excel route. Tested with 5 lines - all worked fine. Its currently running through the whole list.

    Thanks again.
  • rmg1
    rmg1 Posts: 3,149 Forumite
    Part of the Furniture 1,000 Posts Name Dropper
    I know this is sorted, but have you thought about using VBA (Excel's programming language) to move/copy the files for you as the list is in Excel already?
    It's quite straightforward to do (especially the move) and I could probably throw something together in about 10 minutes.
    :wall: Flagellation, necrophilia and bestiality - Am I flogging a dead horse? :wall:

    Any posts are my opinion and only that. Please read at your own risk.
  • Ant555
    Ant555 Posts: 1,591 Forumite
    Part of the Furniture 1,000 Posts Photogenic Name Dropper
    edited 13 May 2014 at 1:28PM
    Thanks rmg1 but the files are on an old timer NT4 server box that I just powered up. (Yes I did say NT4!)

    The files don't show up in windows explorer but can be seen in a command prompt. Copying the 'missing' files off the old box is something I have been meaning to tidy up for ages. Batch file created in Windows 7 lap top, copied to floppy disk, ran on NT4 and worked fine.
This discussion has been closed.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 349.9K Banking & Borrowing
  • 252.7K Reduce Debt & Boost Income
  • 453K Spending & Discounts
  • 242.8K Work, Benefits & Business
  • 619.7K Mortgages, Homes & Bills
  • 176.4K Life & Family
  • 255.8K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16.1K Discuss & Feedback
  • 15.1K Coronavirus Support Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.