PDA

View Full Version : Create hudreds of folders named after a list.txt - Script or Automator or ?




ign
Jun 16, 2009, 12:08 PM
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
Jun 16, 2009, 01:34 PM
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
Jun 16, 2009, 04:54 PM
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!

tbell
Feb 24, 2012, 09:53 AM
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.

Marx55
Jun 24, 2013, 05:28 PM
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
Jun 24, 2013, 10:18 PM
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
Jun 25, 2013, 01:57 AM
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
Jun 25, 2013, 08:33 AM
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.

Marx55
Jun 25, 2013, 02:25 PM
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.

You made my day! Many thanks again!

marbacha
Aug 16, 2013, 08:40 AM
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
Aug 16, 2013, 09:18 AM
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
Aug 16, 2013, 11:34 AM
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
Aug 16, 2013, 11:59 AM
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
Aug 16, 2013, 08:38 PM
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.