Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Create multiple folders from Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create multiple folders from Terminal
Authored by: jaysoffian on Apr 26, '06 09:39:02PM
So as long as we're all posting various ways to do this, here is one that:
  • takes a list of directory (folder) names from a file, one per line
  • doesn't require any special escaping (no need for quotes)
  • doesn't have any problems with unicode
Open TextEdit. Type the names of your folders one per line. Make sure there are no extra lines at the end of the files. Save this as, say "names.txt" (make sure you've done "Format -> Make Plain text" in TextEdit. Then in a terminal window:

python -c 'import sys,os,codecs;[os.mkdir(d) for d in codecs.open(sys.argv[1],"r","macroman")]' names.txt
This assumes that TextEdit uses macroman encoding when you save as plain-text. It did for me. If you've got a UTF8 editor to create names.txt with, then you'd do this instead:

python -c 'import sys,os,codecs;[os.mkdir(d) for d in codecs.open(sys.argv[1],"r","utf8")]' names.txt
I was unable to make Perl's mkdir work properly with unicode. And I don't know ruby well enough, though I'd be happy to see a ruby contribution.

j.

[ Reply to This | # ]

Create multiple folders from Terminal
Authored by: jaysoffian on Apr 26, '06 09:45:30PM
Ah, just realized you set the encoding in TextEdit when you save. In that case, select "UTF-8" and just use:

python -c 'import sys,os;[os.mkdir(d) for d in open(sys.argv[1])]' names.txt
Oddly, if you re-open that that file TextEdit, it improperly decodes it as MacRoman. Oh well.

[ Reply to This | # ]
Create multiple folders from Terminal
Authored by: jaysoffian on Apr 26, '06 09:48:36PM

Okay, I win the award for replies to self. :-)

TextEdit -> Preferences -> Open and Save -> Plain text file encoding.

I had both opening/saving set to Automatic. Setting to UTF-8 does the right thing.

j.



[ Reply to This | # ]
Create multiple folders from Terminal
Authored by: jaysoffian on Apr 26, '06 09:53:18PM
If you use UTF-8 when saving in TextEdit, this perl invocation will work:

perl -ple 'mkdir($_)' names.txt
:-)

[ Reply to This | # ]