Reputation: 5178
First, I should mention that have a windows machine.
Now, I want to copy files that have until
as some part of their file names.
I have a folder named my data
. I have several folders in it where they have four digits in the end of their names, such as my_folder_0000
. I would like to find these folders, and copy the file with until
being some part of their file names into another folder.
To clarify, please see the following example to better understand the structure:
my data/
|-- /my_folder_0000/my_file_until_2010.csv
|-- /his_folder_0001/his_file_until_2011.csv
|-- /test
|-- /documents
In the above example, I would like to go through the first two folders, copy the files into my folder on desktop.
I would like to have a script which works for windows. Thank you!
Upvotes: 0
Views: 1649
Reputation: 735
This should give you an idea how to do it:
@echo off& setlocal
for /d %%d in ("%~1\*.*") do set dir=%%d& call :next_dir %2
exit /b
:next_dir
for /f "delims=0123456789" %%i in ("%dir:~-4%") do exit /b
copy /y "%dir%\*until*.*" %1 | find "until"
At command line 1st arg is source directory (perhaps "\my data" in your case) and 2nd argument is destination directory for the copied files.
Existing/duplicate-named files are overwritten in destination without prompting. Filenames are displayed as they are copied.
Upvotes: 1