Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: HELP: move files into folders based on file prefix  (Read 2469 times)

0 Members and 1 Guest are viewing this topic.

doogin

    Topic Starter


    Newbie

    HELP: move files into folders based on file prefix
    « on: November 10, 2008, 10:50:48 AM »
    I've got a directory of 7,000 images organized into 300 groups based on numerical prefixes in ONE FOLDER:

    0001-file_a.jpg
    0001-file_b.jpg
    0001-file_c.jpg

    0002-file_a.jpg

    0003-file_a.jpg
    0003-file_b.jpg

    I need to get all these files into a folder structure based on their prefix i.e. all the 0001 jpg's into an 0001 folder

    any ideas? MUCH APPRECIATED!!!!!!!!!!!

    --- revision
    I know the folders can be made/named quickly using any folder creating program, but curious if this can be done easily in dos also. Moving the files into the directories is the main obstacle. Thanks!
    « Last Edit: November 10, 2008, 12:12:43 PM by doogin »

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: HELP: move files into folders based on file prefix
    « Reply #1 on: November 10, 2008, 12:34:12 PM »
    This may help you out:

    Code: [Select]
    @echo off
    setlocal enabledelayedexpansion
    for /f "tokens=* delims=" %%x in ('dir /b *.jpg') do (
    set fldr=%%x
    set fldr=!fldr:~0,4!
    if not exist !fldr! md !fldr!
    copy %%x !fldr!
    )

    Batch file should be run from same directory where the jpg files are. Note: as a precaution used copy instead of move. If you're satisfied with the results you can delete the jpg files with del *.jpg

    Paths can be  added to the code as appropriate.  8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    doogin

      Topic Starter


      Newbie

      Re: HELP: move files into folders based on file prefix
      « Reply #2 on: November 10, 2008, 01:12:05 PM »
      THANK YOU THANK YOU THANK YOU

      that was awesome.

      All in total, you just saved me from manually organizing over 33,000 documents.