Batch file to copy files to multiple folders

October 11, 2011 at 15:28:48
Specs: Windows XP
I have a set of text files in one folder which the file name is combined by 2 fields. I want to sort the file name and copy them to existing corresponded folders as the filename indicated.

For example:

Now we have the following folders
\A1 (contains multiple text files)
\abcd\1111
\abcd\2222
\xyzw\3333
\xyzw\4444

Copy files from A1 to others
\A1\abcd_1111.txt ------> to existing folder: \abcd\1111\abcd_1111.txt
\A1\abcd_2222.txt ------> to existing folder: \abcd\2222\abcd_2222.txt
\A1\xyzw_3333.txt ------> to existing folder: \xyzw\3333\xyzw_3333.txt
\A1\xyzw_4444.txt ------> to existing folder: \abcd\4444\xyzw_4444.txt

Thanks


See More: Batch file to copy files to multiple folders

Report •

#1
October 13, 2011 at 08:51:35
Untested:
for %%a in (*_*.lnk) do for /f "tokens=1,2 delims=_" %%A in ("%%~Na") do (
  md "%%A\%%B" 2>NUL
  move "%%~Fa" "%%A\%%B"
)

How To Ask Questions The Smart Way


Report •
Related Solutions


Ask Question