Script Center > Scripting Forums > The Official Scripting Guys Forum! > Script to Sort folders into parent folders
Ask a questionAsk a question
 

QuestionScript to Sort folders into parent folders

  • Wednesday, July 01, 2009 5:44 PMMikedx Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Scenario:

    I have 500+ folders named with a distinct number and name (1234_John Smith) which need to be sorted into parent folders based upon a list that I have in an excel spreadsheet.  The only reliable match between the list and the folder names is the number.  For tasks where there is no "~John Smith" in the folder name, I use a little batch file like this for each parent folder:

    md "PoolA"
    for /f %%a in (PoolAList.txt) do (
    Move "*%%a*" "PoolA\%%a")

    This little script works very well but causes me to lose the "John Smith" in the folder name.

    I am gathering that a .vbs script would better suit my need to actually move folders around but I know next to nothing on the subject.  Basically, I would like a script that I could place in the main directory (the one with all of the 1234_John Smith folders) which would:
    1.  Create a new folder
    2.  Look at a .txt file with a bunch of numbers in it
    3.  Place all folders that correspond to a number in the .txt file into the created folder (without renaming the moved-folder in any way)

    I'm hoping that this is as easy as I think it is.  Thanks in advance for any help!

All Replies

  • Thursday, July 02, 2009 3:32 AMSalvador Manaois IIIModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    You can actually skip the file name in the destination of your MOVE call:

    md "PoolA"
    for /f %%a in (PoolAList.txt) do (
    Move "*%%a*" "PoolA")

    This should retain the whole file name, you won't lose the "Josh Smith" as in your example above.

    Regards,

    Salvador Manaois III
    MCITP | Enterprise & Server Administrator
    MCSE MCSA MCTS(x5) CIWA C|EH
    My Blog: Bytes and Badz 
    My Shots: View My PhotoStream
  • Thursday, July 02, 2009 12:29 PMMikedx Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Salvador,

    Thank you for responding!

    I tried what you suggested but am getting an error in the command window:  "The filename, directory name or volume label syntax is incorrect."  I think the problem is that I am attempting to move folders/directories (and the files contained therein) and not files?  My understanding is that I couldn't actually "move" directories with a batch file - that I could only rename the directory... the problem being that I need to retain the rest of the directory name when moving.

    Any further advice would be MUCH appreciated.

    Thank you again,
    Mike