Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ign

macrumors member
Original poster
Mar 16, 2004
37
1
Firenze
Hello,

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!
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
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.

-Lee
 

ign

macrumors member
Original poster
Mar 16, 2004
37
1
Firenze
Yup!

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!
 
  • Like
Reactions: micros

tbell

macrumors newbie
Jun 25, 2009
5
0
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.
 

Attachments

  • OpenTerminalHere.app.zip
    70.6 KB · Views: 2,810
Last edited:

Marx55

macrumors 68000
Jan 1, 2005
1,913
753
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.

The "OpenTerminalHere.app" 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 OpenTerminalHere.app:

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

How to fix that? Thanks.
 

ChrisA

macrumors G5
Jan 5, 2006
12,541
1,653
Redondo Beach, California
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)}'....

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.
 

Marx55

macrumors 68000
Jan 1, 2005
1,913
753
Yup!
here's the magical line I used in terminal:

cat dirlist.txt | xargs mkdir

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
sudo
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.

----------

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.

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 Editor.app, I get:

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

How to fix it? Thanks.
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
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
sudo
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 Editor.app, I get:

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

How to fix it? Thanks.

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.
 

Attachments

  • Picture 8.png
    Picture 8.png
    88.7 KB · Views: 2,124
Last edited:

Marx55

macrumors 68000
Jan 1, 2005
1,913
753
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.

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!
 
Last edited:

marbacha

macrumors newbie
Oct 22, 2009
6
0
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.
 

marbacha

macrumors newbie
Oct 22, 2009
6
0
Make Folders from a text file

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

In this webpage (http://macgrunt.com/2011/10/25/create-folders-from-list-ii/), 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.

Cheers

and THANKS to the contributor at macgrunt.com.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
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?

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).

Actually it does.
 

Red Menace

macrumors 6502a
May 29, 2011
578
226
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.
 

MacGrunt

macrumors newbie
Jul 25, 2011
7
0
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?

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 : http://macgrunt.com/2011/10/05/create-folders-from-list/

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

m.
 

Master-D

macrumors member
Jun 16, 2008
87
3
London, UK
Thank you, you absolute legends!

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

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.
 

Master-D

macrumors member
Jun 16, 2008
87
3
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.


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.

You made my day! Many thanks again!
 

giuliano73

macrumors newbie
Sep 8, 2018
1
0
Yup!

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!

Thanks for help! But I can't understand where you have to past the line "cat dirlist.txt | xargs mkdir" in Terminal... :confused:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.