1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

How to batch copy files from one folder to another

Discussion in 'Windows 10' started by mohittomar13, Oct 11, 2018.

Thread Status:
Not open for further replies.
Advertisement
  1. mohittomar13

    mohittomar13 Thread Starter

    Joined:
    May 2, 2011
    Messages:
    267
    First Name:
    Mohit Tomar
    hi all.!!

    Actually, I want to help my elder cousin brother this time. He has been given a task to create a new folder and copy about 1600 photographs from a folder that contains about 3700 photographs. He has a list of the file names that he need to copy in a separate *.txt file.

    He can do it manually by opening the main photograph folder searching for the filename and then copying that to a separate folder. But that would take a lot of time and efforts. I was wondering there must be a better way to do it.

    It would be better if a command could copy the file name from the Text file, searches for it in the main photograph folder and when it founds the file matching the name then copies that file to a separate folder.

    Is there any cmd command (Windows 10) or a Linux Bash command to do the job instead of doing it manually. If anyone knows a better way to do this then please do mention it as it will save a lot of time and efforts.

    Thanks in advance.

    Please excuse my English, as it is not my first language, I guess I was able to explain the problem. However, if any more detail is needed please do let me know.
     
  2. mohittomar13

    mohittomar13 Thread Starter

    Joined:
    May 2, 2011
    Messages:
    267
    First Name:
    Mohit Tomar
    Actually I use Kubuntu and my brother use Windows 10. So we can use any of the system. He has the folder in his system. But if the solution requres a linu machine then we can copy that folder to my machine.
     
  3. TerryNet

    TerryNet Moderator

    Joined:
    Mar 23, 2005
    Messages:
    76,988
    First Name:
    Terry
    I doubt that there is a command to do this. However, it should not be too difficult to write a loop which, each time through the loop, reads a line of the .txt file and copies the file named on that line from the source to destination folder.

    Bash is based on the Bourne shell; if it weren't so darn long since I used it I would write a script now. It probably can be done in Windows (Power Shell or Command Prompt) also.
     
  4. mohittomar13

    mohittomar13 Thread Starter

    Joined:
    May 2, 2011
    Messages:
    267
    First Name:
    Mohit Tomar
    Thanks for your reply. Is there a way to do it in C#. I just started learning C# as a hobby and can understand most of the basic c# programming codes (not too advanced). I strongly believe this could be done by writing some console application that uses stream reader and writer. If anyone can guide me to use any class or method from the standard library that would be nice. As I'm not yet familiar with most of the pre-existing classes and methods in c#. I will also learn something new and at the same time, a useful tool will be created.
     
    Last edited: Oct 12, 2018
  5. TerryNet

    TerryNet Moderator

    Joined:
    Mar 23, 2005
    Messages:
    76,988
    First Name:
    Terry
    Wish I could help, but I've forgotten most of what I knew of C, and never really got a good handle on C++ or classes, methods, etc.
     
  6. mohittomar13

    mohittomar13 Thread Starter

    Joined:
    May 2, 2011
    Messages:
    267
    First Name:
    Mohit Tomar
    No problem. Thanks by the way. :)
     
  7. TerryNet

    TerryNet Moderator

    Joined:
    Mar 23, 2005
    Messages:
    76,988
    First Name:
    Terry
    You're welcome. :)
     
  8. lunarlander

    lunarlander

    Joined:
    Sep 21, 2007
    Messages:
    9,406
    If the file names in that text file are in one single column, like this:

    photo1.jpg
    photo2.jpg
    photo3.jpg

    Then change the first line to this:

    copy photo1.jpg \newfolder\*.*

    Then highlight the word 'copy', press CTRL-C
    Cursor down one row, press Home key and then press CTRL-V
    Repeat till you reach bottom line of text file.

    Then go back to the first line, and highlight "\newfolder\*.*"
    Cursor down one row, press End key and then press CTRL-V
    Repeat till you reach the bottom of the text file

    Save text file as file with a BAT extension.
    Run the bat file
     
    TerryNet likes this.
  9. TerryNet

    TerryNet Moderator

    Joined:
    Mar 23, 2005
    Messages:
    76,988
    First Name:
    Terry
    Thanks, lunarlander. I like that. Now, if mohittomar13 doesn't have the stamina to follow that procedure on a 1,600 line file ...

    Copy the .txt file to the Linux machine. In a Terminal window use the VI editor as follows.

    vi file.txt
    :1,$s/\(.*\)/copy \1 \\newfolder\\\1/
    :w file.bat
    :q


    Be careful to use a blank space where, and only where, it appears in those commands.

    You've now left the file.txt ("file" can be any name) unchanged and written a new file called file.bat that can be copied back to the Windows machine and run as lunarlander said.

    In the critical line above 1,$s means to substitute (replace) on all lines the matched stuff between the first two slashes with the stuff specified between the second and third slashes.\1

    \( and then \) mark the stuff bracketed between them.
    .* means match any character as many times as possible (that is, match everything on the line).
    \1 means use the first marked stuff.
    \\ means to use the \ character.
     
  10. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1217688

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice