I made a batch file that allows me to copy and rename (in that order) files based on a txt or csv-file. In column 1, there is the original filename, in column 2 the new name. This allows me to copy and rename only the files that I need.
It works very fine, but it has a limitation: for now I can only copy files from one directory, the main directory. I would like to be able to only copy the files, independently if they are in the main or its subdirectories. In other words, it should search the files in both the main directory and subdirectories.
Below the code:
for /f "tokens=1,2 delims=," %%j in (basefile.txt) do (
copy "%%j" destinationfolder/%%k
)
I have looked and tried combinations with /r or /s etc.
It is probably some easy addition, but I just can't figure it out... Thanks
This should copy the files in the folder tree to the destination.
It's not perfect as a false match is possible if the filespec is not unique, and matches within the short filenames are possible too if the filename is not specific enough.
@echo off
for /f "tokens=1,* delims=," %%j in (basefile.txt) do (
for /r "d:\base\folder" %%a in ("%%j") do (
copy "%%a" "d:\destinationfolder\%%k"
)
)