Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 16, 2009, 12:08 PM   #1
ign
macrumors member
 
Join Date: Mar 2004
Location: Firenze
Create hudreds of folders named after a list.txt - Script or Automator or ?

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!
ign is offline   0 Reply With Quote
Old Jun 16, 2009, 01:34 PM   #2
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: 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
lee1210 is offline   0 Reply With Quote
Old Jun 16, 2009, 04:54 PM   #3
ign
Thread Starter
macrumors member
 
Join Date: Mar 2004
Location: 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!
ign is offline   1 Reply With Quote
Old Feb 24, 2012, 09:53 AM   #4
tbell
macrumors newbie
 
Join Date: Jun 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
File Type: zip OpenTerminalHere.app.zip (70.6 KB, 457 views)

Last edited by tbell; Feb 24, 2012 at 09:59 AM.
tbell is offline   1 Reply With Quote
Old Jun 24, 2013, 05:28 PM   #5
Marx55
macrumors 6502a
 
Join Date: Jan 2005
Quote:
Originally Posted by tbell View Post
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.
Marx55 is offline   0 Reply With Quote
Old Jun 24, 2013, 10:18 PM   #6
ChrisA
macrumors G4
 
Join Date: Jan 2006
Location: Redondo Beach, California
Quote:
Originally Posted by lee1210 View Post
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.
ChrisA is offline   0 Reply With Quote
Old Jun 25, 2013, 01:57 AM   #7
Marx55
macrumors 6502a
 
Join Date: Jan 2005
Quote:
Originally Posted by ign View Post
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.

----------

Quote:
Originally Posted by ChrisA View Post
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.
Marx55 is offline   0 Reply With Quote
Old Jun 25, 2013, 08:33 AM   #8
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Quote:
Originally Posted by Marx55 View Post
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.
Attached Thumbnails
Click image for larger version

Name:	Picture 8.png
Views:	149
Size:	88.7 KB
ID:	419728  
__________________
Space Corps Directive 34124

Last edited by kryten2; Jun 25, 2013 at 08:38 AM.
kryten2 is offline   0 Reply With Quote
Old Jun 25, 2013, 02:25 PM   #9
Marx55
macrumors 6502a
 
Join Date: Jan 2005
Quote:
Originally Posted by kryten2 View Post
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!
Marx55 is offline   0 Reply With Quote
Old Aug 16, 2013, 08:40 AM   #10
marbacha
macrumors newbie
 
Join Date: Oct 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.
marbacha is offline   0 Reply With Quote
Old Aug 16, 2013, 09:18 AM   #11
marbacha
macrumors newbie
 
Join Date: Oct 2009
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/creat...-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.
marbacha is offline   0 Reply With Quote
Old Aug 16, 2013, 11:34 AM   #12
subsonix
macrumors 68030
 
Join Date: Feb 2008
What is the typical use case for needing to create hundreds of empty folders? Doesn't it take about as long to create the text file with the names typed in, as to create the folders manually?

Quote:
Originally Posted by marbacha View Post
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.
subsonix is offline   0 Reply With Quote
Old Aug 16, 2013, 11:59 AM   #13
Red Menace
macrumors 6502
 
Join Date: May 2011
Location: 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.
__________________
MacBook Pro / OS X Mavericks (10.9.4) / Xcode 5.1.1 / RubyMotion FTW
Red Menace is offline   0 Reply With Quote
Old Aug 16, 2013, 08:38 PM   #14
MacGrunt
macrumors newbie
 
Join Date: Jul 2011
Quote:
Originally Posted by subsonix View Post
What is the typical use case for needing to create hundreds of empty folders? 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/creat...ers-from-list/

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

m.
MacGrunt is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
How to Create .TXT Document within Finder curious12 Mac Basics and Help 9 Sep 7, 2013 01:18 PM
How to create list names of folders into Word or PDF ? vim147 Mac Applications and Mac App Store 5 Mar 31, 2013 09:19 AM
App or script that generates a list of files and folders TheGenerous Mac Applications and Mac App Store 2 Nov 14, 2012 09:58 AM
Resolved: Applescript: List/txt.file question h1068 Mac Programming 5 Jul 3, 2012 06:30 PM
Help to create txt file of tons of images in a folder zenmster Mac Applications and Mac App Store 3 Jun 26, 2012 10:56 AM

Forum Jump

All times are GMT -5. The time now is 04:44 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC