I have a text file with list of directories and I want to copy *.xlsx
files from them to a target folder.
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 an example of folders that I want to look at and find excel files would be
\\internal.company.com\project folder\PT_NAK01
, etc.
However, I don't know 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.
Using xcopy "%main_folder%\%%i\*.xlsx" "%my_folder%"
copies the files from each folder (%%i
) with xlsx
extension to the target folder.
However, I also had an issue with the text file containing the sub-folder names; it needed to be separated with new lines instead of being comma-separated entries.
PT_NAK01
PT_NAK04
PT_NAK05
...
With these changes, this batch-file 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%"
)