cmdxcopy

Copying files with specific extension from a list (text file) of directories


I have a text file with list of certain directories that I want to copy *.xlsx files from them to another directory.

This is how the the text file (list.txt) is arranged:

PT_NAK01, PT_NAK04, PT_NAK05, PT_JAR03

What I have so far:

@echo off
set main_folder="\\internal.company.com\project folder\"
set my_folder="C:\_M__\files"
for /f "tokens=*" %%i in (list.txt) DO (
    xcopy "%main_folder%\%%i" "%my_folder%"
)

So the folders that I want to look into would be \\internal.company.com\project folder\PT_NAK01 etc.

What I don't know is how to pass the specific extension *.xlsx to this command.

Note: I haven't used /S switch with xcopy deliberately because I do not want the files in the sub-directories.

P.S. Solutions in or work for me as well.


Solution

  • One thing that made an error in my example was how I set the text file with the folder names. It should be set up with carriage return as separator instead of comma-separated entries.

    PT_NAK01
    PT_NAK04
    PT_NAK05
    

    etc.

    With that, this batch-file (in reference to MatSnow's and shellter's comments) works fine for the purpose of the question.

    @echo off
    set main_folder="\\internal.company.com\project folder\"
    set my_folder="C:\_M__\files"
    for /f "tokens=*" %%i in (list.txt) DO (
        xcopy "%main_folder%\%%i\*.xlsx" "%my_folder%"
    )
    

    Note: If you want to type this directly into the command line, you don't need double % for the variables.