Create hudreds of folders named after a list.txt - Script or Automator or ?

Discussion in 'Mac Programming' started by ign, Jun 16, 2009.

  1. ign macrumors member

    Mar 16, 2004

    I need to create some hundreds of folders with names from a list (text file).
    I would like to avoid creating and naming them one at a time manually!

    I was wondering if I should use Automator (haven't figured out how though)
    or applescript.

    Has anyone done something like this before? any hints?

    thank you!
  2. lee1210 macrumors 68040


    Jan 10, 2005
    Dallas, TX
    I'm sure this is possible with either of those, but i would go to shell because i know it better.

    cat list.txt | awk '{system("mkdir "$1)}'

    Or something similar.

  3. ign thread starter macrumors member

    Mar 16, 2004

    much better a single line than trying to figuring out a way in Automator...

    here's the magical line I used in terminal:

    cat dirlist.txt | xargs mkdir

    it created about 400 folders with the names found in dirlist.txt
    in a second !

    Thanks again, Lee!
  4. tbell, Feb 24, 2012
    Last edited: Feb 24, 2012

    tbell macrumors newbie

    Jun 25, 2009
    The terminal trick worked great! Thanks! A couple notes:

    1) In dirlist.txt, enclose multiple-word folder names in quotes because otherwise the command makes a folder for each word separated by a space. Ex: ["Test 1"] in the text file creates one folder [Test 1] (without brackets). But just [Test 1] in the text file creates two folders, [Test] and [1].

    2) I had to use this trick to make several hundred folders from a list of cell values in an Excel column. The following steps outline how to do this process:

    - If the cell values have multiple words you'll need an easy way to enclose all the words in quotes. To get quotes around the cell values and a space afterward, create a new column and copy this CONCATENATE function down the new column:

    =CONCATENATE("""",Cell_Reference,""""," ")

    - Where Cell_Reference is the cell with the desired folder name. Due to the way Excel handles quotation marks in its formulas, you need four quotation marks in a row to obtain one quotation mark in the formula result. The above function would return a value of ["Cell_Reference" ] in the forumla cell (without brackets of course, just using to show the space afterward).

    - The next necessary step is to paste the cell values that are currently listed down a column as a row. So copy the range of desired folder names in Excel and from the Edit menu select Paste Special. In the box that opens, select "Values" and check the "Transpose" box, and paste to an empty row. This should line the column values up horizontally. Then copy & paste that row into your plain-text dirlist.txt file and you should be good to run the command.

    3) PS for those not good with Terminal I've included a ZIP of a script you can place in the directory where you want the folders to be (make sure the dirlist.txt is there too) -- it'll open your terminal window there.

    Attached Files:

  5. Marx55 macrumors 68000

    Jan 1, 2005
    The "" does not work for me on Mac with OS X 10.8.4 (Mountain Lion). I place such application in a folder containing the dirlist.txt file which contains, for instance:

    "First name this" "Second name this" "Third name this"

    In such a case, I get the following error when opening

    cd '/Users/me/Desktop/Folder/' && echo $'\ec'
    Illegal variable name.

    How to fix that? Thanks.
  6. ChrisA macrumors G4

    Jan 5, 2006
    Redondo Beach, California
    THat is what I'd do too. Only I like "see" better than "awk".

    "sed" is a kind of text editor. I'd use a text edit command to turn a line from the text file to a shell command to create the folder. The sed editor output is put inside back quotes so it gets executed by the system.

    The other way if this is a one time deal is to use a text editor to manually add "mkdir " to the front of each line then you have transformed the file to a script. Run the script.
  7. Marx55 macrumors 68000

    Jan 1, 2005
    How to use it? If I do it in Terminal I get:
    cat: dirlist.txt: No such file or directory

    If I drag and drop the Folder Text containing dirlist.txt into Terminal and paste
    cat dirlist.txt | xargs mkdir
    and carriage return, I get:
    /Users/me/Desktop/Test: Permission denied.

    If I drag and drop the Folder Text containing dirlist.txt into Terminal, type
    and space and paste
    cat dirlist.txt | xargs mkdir
    and carriage return, I get:
    /Users/me/Desktop/Test: Permission denied.

    Sorry for my ignorance with Terminal. Thanks.


    If I paste
    mkdir aa bb cc
    into the dirlist.txt file and change its name to dirlist.scpt and open and run it with AppleScript, I get:

    Syntax Error
    A identifier can’t go after this identifier.

    How to fix it? Thanks.
  8. kryten2, Jun 25, 2013
    Last edited: Jun 25, 2013

    kryten2 macrumors 6502a

    Mar 17, 2012
    I'm guessing your dirlist.txt file is in folder Test and not in Text? Open Terminal and type in cd followed by a space(I mean cd and press the space bar), drag your Test folder from Finder into the Terminal window and press return. Then type or paste the cat dirlist.txt | xargs mkdir line into the Terminal window and press return.

    Attached Files:

  9. Marx55, Jun 25, 2013
    Last edited: Jun 5, 2016

    Marx55 macrumors 68000

    Jan 1, 2005
    Yes. And it works great with your directions. Many thanks!!!

    Text file (dirlist.txt) generated with BBEdit 10.5.1 - Save as Unix (LF) - Unicode (UTF-8) on Mac.

    When using names of persons (that is, name and surname to become each folder), I had to use quotes and spaces to separate the full name of each person (name and surname) from the ones of the other persons, and the quotes had to be plain like "these" (not smart or curved) for it to work properly. No need to use commas (actually, they should not be used, or they will be also included at the end of the names of the folders!!!).

    You made my day! Many thanks again!
  10. marbacha macrumors newbie

    Oct 22, 2009
    Make Folders from a text file

    I had used an application that generates folders with names listed in a text file.

    In the application, simply select a file saved in text format. The application will pick all these text (paragraph) and name that folder with that text.

    Sorry. The bad news is that was greater than 3 years ago and it should be a PPC application. It have a name (if I recall it well) MakeFolder.

    I have been trying to hunt this for some time now but failed.

    Wish someone here can make such an application. Thank you in advance.
  11. marbacha macrumors newbie

    Oct 22, 2009
    Make Folders from a text file

    After my earlier posting, I found an AppleScript that does it.

    In this webpage (, it is listed two scripts.

    I copy the first, use AppleScript Editor and saved as an application.

    Then, I make a list of folder names I want to create, type it in paragraphs, save it as a Text file (yes, a text format file. TextEdit do not support Save As a text format file).

    I launch the AppleScript made earlier, select the Text File, voila! Folders are created in the same folder as where the Text File was picked.


    and THANKS to the contributor at
  12. subsonix macrumors 68040

    Feb 2, 2008
    What is the typical use case for needing to create hundreds of empty folders? :confused: Doesn't it take about as long to create the text file with the names typed in, as to create the folders manually?

    Actually it does.
  13. Red Menace macrumors 6502

    Red Menace

    May 29, 2011
    Littleton, Colorado, USA
    I suppose it depends on what your workflow is doing. I have an Automator action that can create folder structures from text, but usually it is easier to just copy the structure.
  14. MacGrunt macrumors newbie


    Jul 25, 2011
    As Red Menace says, it depends on your workflow. Where I work I need to create a dozen or two dozen job folders at a time. Copy/pasting the (mostly consecutive) job names from an existing database into a single text file is much, much quicker than copy/pasting the individual names to the individual folders. But, I agree, if you were typing the names in by hand, it wouldn't make too much difference.

    The main one I use is something more like this version — altered to also create a bunch of common subfolders :

    The one that marbacha mentioned was created for someone with different workflow requirements.

  15. Master-D macrumors member

    Jun 16, 2008
    London, UK
    Thank you, you absolute legends!

    Saved a good few hours of work that I can now spend procrastinating :)

  16. Master-D macrumors member

    Jun 16, 2008
    London, UK
    Good tip on BBEdit. You can easily add the prefix/suffix quotation marks you need with this using menu - text - prefix/suffix lines... also saves to a proper text file.

    For those wondering why this might be useful, I needed to make 630 folders based on a web list, so I didn't need to type anything, just copy, paste, strip the hypertext junk, add the quotation marks, and run the terminal code. Saved 630 manual copy and paste operations, each taking 6 or 7 clicks and key combinations. That is a hell of a lot of labour avoided.

    The internet is full of people who help solve problems, they are great, and people who tell you your problems are invalid, they are not so great...

    If anyone in the future is stuck with this feel free to PM for a walkthrough.

  17. giuliano73 macrumors newbie


    Sep 8, 2018
    Thanks for help! But I can't understand where you have to past the line "cat dirlist.txt | xargs mkdir" in Terminal... :confused:

Share This Page

16 June 16, 2009