Batch file that organizes folder

Discussion in 'Scripting' started by spidyfan21, Aug 3, 2011.

  1. spidyfan21

    spidyfan21 MDL Novice

    Aug 3, 2011
    1
    0
    0
    I'm trying to create a .bat file that will make dir #-z and then load *#-*z into there respective folders, it basically looked like this but didn't work correctly

    mkdir a
    mkdir b
    mkdir c
    etc...
    move *a a
    move *b b
    move *c c
    etc...

    what is going wrong?
     
  2. x86

    x86 MDL Addicted

    Jul 8, 2011
    898
    206
    30
    Hello and Welcome to MDL!

    Can't really tell what's wrong if we don't have the actual script you are trying to run / error messages etc etc

    Just a guess, but maybe it could be the syntax that's wrong. Its very easy to make mistake(s) whilst writing such scripts. If that's the case - not to worry - there are endless resources on the topic. Take a look here, here and here ...

    You should be able to work it out :)
     
  3. Compo

    Compo MDL Member

    Mar 29, 2011
    137
    104
    10
    As stated above, we need an actual script. Since you admit to not knowing how to do it you are not in a position to decide what information you can fail to give in order to receive a working solution.

    Provide a real directory structure with real file names, you are not moving items ending with a, b or c into directories named a, b or c, especially because those directories match your move specification. (you cannot move a directory named *a into directory a because they are one and the same thing).
     
  4. Psychlone

    Psychlone MDL Novice

    Dec 1, 2011
    1
    0
    0
    Try this

    @echo off
    SET dsk=%userprofile%\Desktop
    cd %dsk%
    set TD="%dsk%\Desktop Clearout\From %DATE%"
    if not exist "%TD%\nul"
    Mkdir %TD%
    setlocal ENABLEDELAYEDEXPANSION
    FOR %%f IN (*.*) DO (
    set t=%%f
    if not exist "%TD%\!t:~-3!\nul"
    Mkdir %TD%\!t:~-3!
    move "!t!" %TD%\!t:~-3!
    )


    It'll create a "Desktop Clearout" folder on your desktop and remove files on the desktop to it and organise them according to type. I'm guessing it's something like this you're looking for. Very useful if (like me) you habitually clutter your desktop with all kinds of rubbish you can't be bothered to sort ot just now.
     
  5. nephi12

    nephi12 MDL Novice

    Jul 3, 2013
    4
    0
    0
    md a
    md b
    move "*a" a
    move "*b" b