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: shadowofged on Apr 25, '06 12:25:07PM
Here's a way to do it that will create folders even if your list of names have spaces. The file dir_list.txt contains a list of directory names, one per line. Here goes:

cat dir_list.txt | while read FILE
do
    mkdir "${FILE}"
done

That should work for all files, spaces or not.

[ Reply to This | # ]
Create multiple folders from Terminal
Authored by: osxpounder on Apr 25, '06 02:13:44PM

Well, dangit, it didn't work for me. Maybe I goofed, but here's what I did:

Created a plain text document in TextEdit, saved as plain text, UTF-8.

In the same folder, I opened a Terminal, and used pico to create a text file that contained your script. I changed the name of the list.txt file to match mine.

Saved out of pico to a file called "do". I chmoded "do" 0700.

Then I typed:

./do

Nothing happened. No errors, no new folders.

---
--
osxpounder



[ Reply to This | # ]
Create multiple folders from Terminal
Authored by: suarez on Apr 25, '06 04:01:42PM

Do is a reserved word in bash. See the reserved words section in the bash man page. If you change the script name to anything else that's not a reserved bash word, it works.



[ Reply to This | # ]
Create multiple folders from Terminal
Authored by: osxpounder on Apr 26, '06 12:24:22PM
Thanks for the tip. I renamed it to "herbie", but still, same results -- i.e, none, not even an error message.

herbie's contents:

cat list.txt | while read FILE

do

mkdir "${FILE}"

done

I'm using bash.

---
--
osxpounder

[ Reply to This | # ]

Create multiple folders from Terminal
Authored by: merlyn on Apr 30, '06 03:35:21PM

Both uses of "cat file | ..." in this thread are "useless use of cat". Google for that for details. In other words, sloppy coding, time to learn to clean up your messes.



[ Reply to This | # ]