Solved Need Batch file2copy files to directories

May 16, 2011 at 17:07:46
Specs: Windows XP
I have many files in a single directory, e.g., A001.txt, A002.txt, A003.txt, etc. I need to copy or move these individual files into directories with the same names, e.g., folder A001, A002, A003, etc. Thanks in advance for your help.

See More: Need Batch file2copy files to directories

Report •


#1
May 17, 2011 at 02:51:19
✔ Best Answer
Test this - untested.

@echo off
cls
setlocal

pushd path\to\files\||echo Pushd failed - job terminated.&& exit /b

set output=path\to\output\folder

for /f "delims=*" %%1 in ('dir /b *.txt') do (
    if not exist %output%\%%~n1\ md %output%\%%~n1
    copy %%1 %output%\%%~n1\
)

popd 


Please come back & tell us if your problem is resolved.


Report •

#2
May 18, 2011 at 08:57:23
Wow! Works like a charm. Thanks so much Wahine.

Report •

#3
May 19, 2011 at 19:13:53
You're welcome & thanks for coming back to report your success.


Please come back & tell us if your problem is resolved.


Report •

Related Solutions


Ask Question