Click here for important information about

Batch file to create and move files

October 10, 2011 at 15:52:28
Specs: Windows XP
I hope someone can help. I have about more than 700 folders in 9xxxxx format. In each folder, there are multiple text files. We want to go into each folder, create sub-folders based on file names and move the text files into the sub-folders. So far, for that part, I have created the script below to create and move files. However, I want to repeat that in multiple 9xxxx folders. How?

@echo off
for /f %%F in ('dir/b/a-d *.TXT') do call :sub1 %%F
goto :eof
set name=%1
md %name:~0,6%
move %* %name:~0,6%




See More: Batch file to create and move files

October 11, 2011 at 02:45:44
@echo off
setLocal EnableDelayedExpansion
set root=%CD%
for /f "tokens=* delims=" %%a in ('dir /AD /B') do (
set /a q+=1
set folder_name!q!=%%a
for /l %%a in (1,1,%q%) do (
cd "!folder_name%%a!"
for /f "tokens=* delims=" %%b in ('dir /B *.txt') do (
set name=%%~nb
set name=!name:~0,6!
if not exist !name! (
md !name!
move !name!*.txt !name!
cd "%root%"

Report •

October 11, 2011 at 15:12:45
Thank you MoneyMoney for your help. Your script works like a charm!

Report •
Related Solutions

Ask Question