Computing.Net > Forums > Programming > Automaticly organize folders

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Automaticly organize folders

Reply to Message Icon

Name: BatchFreak
Date: November 4, 2008 at 14:32:31 Pacific
OS: Windows Xp Pro
CPU/Ram: 2.4 ghz/ 512 mb
Product: Dell
Comment:

I am attempting to create a Batch file that will automaticly create sub-directories based on file type and move the files there. So far I have this, but it freezes after i type in my directory, any ideas?

@ECHO OFF
TITLE Folder Sorter
COLOR 09
SET 1=0
SET 2=0
SET 3=0
SET 4=0
SET /p dir=What folder?
CD %dir%
PAUSE
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:start
SET /a 1=%1%+1
IF %1%==37 (
SET 1=1
SET /a 2=%2%+1
)

IF %2%==37 (
SET 2=1
SET /a 3=%3%+1
)

IF %3%==37 (
SET 3=1
SET /a 4=%4%+1
)

IF %4%==37 EXIT
PAUSE
REM~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
IF %1%==0 SET a=
IF %1%==1 SET a=a
IF %1%==2 SET a=b
IF %1%==3 SET a=c
IF %1%==4 SET a=d
IF %1%==5 SET a=e
IF %1%==6 SET a=f
IF %1%==7 SET a=g
IF %1%==8 SET a=h
IF %1%==9 SET a=i
IF %1%==10 SET a=j
IF %1%==11 SET a=k
IF %1%==12 SET a=l
IF %1%==13 SET a=m
IF %1%==14 SET a=n
IF %1%==15 SET a=o
IF %1%==16 SET a=p
IF %1%==17 SET a=q
IF %1%==18 SET a=r
IF %1%==19 SET a=s
IF %1%==20 SET a=t
IF %1%==21 SET a=u
IF %1%==22 SET a=v
IF %1%==23 SET a=w
IF %1%==24 SET a=x
IF %1%==25 SET a=y
IF %1%==26 SET a=z
IF %1%==27 SET a=0
IF %1%==28 SET a=1
IF %1%==29 SET a=2
IF %1%==30 SET a=3
IF %1%==31 SET a=4
IF %1%==32 SET a=5
IF %1%==33 SET a=6
IF %1%==34 SET a=7
IF %1%==35 SET a=8
IF %1%==36 SET a=9
PAUSE
REM~~~~~~~~~~~~~~~~
IF %2%==0 SET b=
IF %2%==1 SET b=a
IF %2%==2 SET b=b
IF %2%==3 SET b=c
IF %2%==4 SET b=d
IF %2%==5 SET b=e
IF %2%==6 SET b=f
IF %2%==7 SET b=g
IF %2%==8 SET b=h
IF %2%==9 SET b=i
IF %2%==10 SET b=j
IF %2%==11 SET b=k
IF %2%==12 SET b=l
IF %2%==13 SET b=m
IF %2%==14 SET b=n
IF %2%==15 SET b=o
IF %2%==16 SET b=p
IF %2%==17 SET b=q
IF %2%==18 SET b=r
IF %2%==19 SET b=s
IF %2%==20 SET b=t
IF %2%==21 SET b=u
IF %2%==22 SET b=v
IF %2%==23 SET b=w
IF %2%==24 SET b=x
IF %2%==25 SET b=y
IF %2%==26 SET b=z
IF %2%==27 SET b=0
IF %2%==28 SET b=1
IF %2%==29 SET b=2
IF %2%==30 SET b=3
IF %2%==31 SET b=4
IF %2%==32 SET b=5
IF %2%==33 SET b=6
IF %2%==34 SET b=7
IF %2%==35 SET b=8
IF %2%==36 SET b=9
PAUSE
REM ~~~~~~~~~~~~~~~~~~~~~
IF %3%==0 SET c=
IF %3%==1 SET c=a
IF %3%==2 SET c=b
IF %3%==3 SET c=c
IF %3%==4 SET c=d
IF %3%==5 SET c=e
IF %3%==6 SET c=f
IF %3%==7 SET c=g
IF %3%==8 SET c=h
IF %3%==9 SET c=i
IF %3%==10 SET c=j
IF %3%==11 SET c=k
IF %3%==12 SET c=l
IF %3%==13 SET c=m
IF %3%==14 SET c=n
IF %3%==15 SET c=o
IF %3%==16 SET c=p
IF %3%==17 SET c=q
IF %3%==18 SET c=r
IF %3%==19 SET c=s
IF %3%==20 SET c=t
IF %3%==21 SET c=u
IF %3%==22 SET c=v
IF %3%==23 SET c=w
IF %3%==24 SET c=x
IF %3%==25 SET c=y
IF %3%==26 SET c=z
IF %3%==27 SET c=0
IF %3%==28 SET c=1
IF %3%==29 SET c=2
IF %3%==30 SET c=3
IF %3%==31 SET c=4
IF %3%==32 SET c=5
IF %3%==33 SET c=6
IF %3%==34 SET c=7
IF %3%==35 SET c=8
IF %3%==36 SET c=9
PAUSE
REM ~~~~~~~~~~~~~~~~
IF %4%==0 SET d=
IF %4%==1 SET d=a
IF %4%==2 SET d=b
IF %4%==3 SET d=c
IF %4%==4 SET d=d
IF %4%==5 SET d=e
IF %4%==6 SET d=f
IF %4%==7 SET d=g
IF %4%==8 SET d=h
IF %4%==9 SET d=i
IF %4%==10 SET d=j
IF %4%==11 SET d=k
IF %4%==12 SET d=l
IF %4%==13 SET d=m
IF %4%==14 SET d=n
IF %4%==15 SET d=o
IF %4%==16 SET d=p
IF %4%==17 SET d=q
IF %4%==18 SET d=r
IF %4%==19 SET d=s
IF %4%==20 SET d=t
IF %4%==21 SET d=u
IF %4%==22 SET d=v
IF %4%==23 SET d=w
IF %4%==24 SET d=x
IF %4%==25 SET d=y
IF %4%==26 SET d=z
IF %4%==27 SET d=0
IF %4%==28 SET d=1
IF %4%==29 SET d=2
IF %4%==30 SET d=3
IF %4%==31 SET d=4
IF %4%==32 SET d=5
IF %4%==33 SET d=6
IF %4%==34 SET d=7
IF %4%==35 SET d=8
IF %4%==36 SET d=9
PAUSE
REM ~~~~~~~~~~~~~~~~~
IF EXIST *.%a%%b%%c%%d% (
MD %a%%b%%c%%d%
MOVE *.%a%%%%3%%4% %a%%b%%c%%d%
)
GOTO start



Sponsored Link
Ads by Google

Response Number 1
Name: klint
Date: November 4, 2008 at 15:06:00 Pacific
Reply:

I don't know why it freezes, but one thing I can advise is to avoid having variables named 1, 2 etc. That's because %1, %2 etc are the batch file's command-line arguments. So when you say %1% it doesn't look at the variable, it looks at the first command-line argument and adds a % at the end.


0

Response Number 2
Name: BatchFreak
Date: November 4, 2008 at 16:08:52 Pacific
Reply:

That might be it Ill see.... thank you it was that and the fact that set /a doesnt like numeric variables.

Dear lord this takes a looong time :D

I only Batch if possible, 2000 more lines of code, oh well.


0

Response Number 3
Name: Holla
Date: November 4, 2008 at 23:50:38 Pacific
Reply:

I was thinking about whether the above batch file is too long.... and on the line of optimising it with subroutines, and I encountered one problem.


set alpha=abcdefghijklmnopqrstuvwxyz0123456789
for /l %%I in (1,1,37) do set d=%alpha:~%%I,1%


which of course does not work.
It does not like another environment variable or FOR variable inside an "Environment variable substitution"

Is that how it is or am I missing something?

--
Holla.


0

Response Number 4
Name: klint
Date: November 5, 2008 at 02:37:43 Pacific
Reply:

To Holla,

You need to do

setlocal enabledelayedexpansion
set alpha=abcdefghijklmnopqrstuvwxyz0123456789
for /l %%I in (0,1,36) do (
set d=!alpha:~%%I,1!
echo d=!d!
)


0

Response Number 5
Name: Holla
Date: November 5, 2008 at 09:07:46 Pacific
Reply:

Thanks klint for that quick reply.

BatchFreak,

I think all you need is this: It will be fast too:


@echo off
setlocal enabledelayedexpansion
for %%a in (*.*) do (
set dirname=%%~xa
md !dirname:~1! 2> nul
move *%%~xa !dirname:~1!
)
endlocal

:Just ignore the error message about duplicate directory (when you have more than one file with same extension)

--
Holla.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Automaticly organize folders

Batch File: For Command Syntax www.computing.net/answers/programming/batch-file-for-command-syntax/9262.html

name folder automatically with ~ www.computing.net/answers/programming/name-folder-automatically-with-/14723.html

Creating folders automatically! www.computing.net/answers/programming/creating-folders-automatically/17214.html