Move files depending on extension

Microsoft / Dos
July 8, 2010 at 07:53:29
Specs: Windows XP, 2gb
Hi,

I am trying to write a batch script that moves a selection of files into sub directories based on the file extension. EG dir contains
1.txt 2.bat 3.txt 4.usr 5.1.jfifj

I want the txt files moved into a txt folder, bat into a bat folder, usr moved into a usr folder, jfifj into the jfifj folder.

I could hard code it but there might be other file types going into the directory in the future also the extension can be more than 3 charecters and also the file name can contain more than 1 . (dot) eg 1.1.txt.

Thanks

Paul

Thanks and Regards

Paul


See More: Move files depending on extension

Report •

#1
July 8, 2010 at 09:23:04
this is a test


=====================================
Helping others achieve escape felicity

M2


Report •

#2
July 9, 2010 at 00:54:01
What you testing for?

Thanks and Regards

Paul


Report •

#3
July 9, 2010 at 18:42:03
@echo off & setlocal
for /f "tokens=*" %%a in ('dir /b /a-d') do (
md %%~xa
:: or "move" if you prefer, in foll line
copy %%a %%~xa
)
::------- end
might work, not tested with multiple dots etc.
add /s to the "dir" and the root to the created subdirs if you want recursive operation. No allowances for already-existing filenames (see recent post about copy w/renumber for that).

Report •

Related Solutions

#4
July 12, 2010 at 13:46:48
I was testing to find out if I could post. Been broke for several days.

=================================

@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b/a-d') do (
if "%%~Xa" neq "" (
set X=%%~Xa
set D=!X:~1!
if not exist !D! echo md !D!
echo move "%%a" !D!
)
)


=====================================
Helping others achieve escape felicity

M2


Report •

Ask Question