Forum Moderators: travelin cat

Message Too Old, No Replies

Folder Names (batching)

         

mboydnv

7:42 pm on Sep 26, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



Can anyone suggest a nice way for me to name 8oo folders from a text file of keywords?

I have a BBedit text doc with 800 keywords:

keyword1
keyword2

etc

and i want to name 800 folders (from untitled) using these keywords. I'm not savvy enough with applescript and have not seen any programs that will do this on versiontracker.com

I need to put these 800 folders up as directories on a website...any suggestions?

Cheers!

BjarneDM

5:42 am on Sep 27, 2004 (gmt 0)

10+ Year Member



The simples way I can think of is using the Terminal:

cd <directory_where_to_create>
cat <file_of_keywords> ¦ xargs mkdir

(as usual, the ¦ is what you get when you press [cmd/apple]i )

If you haven't messed around with Terminal before, the simplest way of doing this is to have both a Terminal and a Finder window open at the same time. Then, type 'cd ' (remember the [space]) in the Terminal window and subsequently drag the directory from the Finder window to the Terminal window. Same procedure for 'cat '.

If you want to know what's behind these commands, type 'man <command>' in Terminal, where <command> is any of these four: cd , cat , xargs , mkdir

coolmacguy

6:28 am on Sep 27, 2004 (gmt 0)

10+ Year Member



[quote=BjarneDM](as usual, the ¦ is what you get when you press [cmd/apple]i )[/quote]

What do you mean here?

Typing command-i does not enter the pipe character in Terminal. It opens the inspector window. Generally pipe is Shift-\ for keyboards where pipe ¦ and slash \ and on the same key.

BjarneDM

10:45 am on Sep 27, 2004 (gmt 0)

10+ Year Member



My fault :(

The correct statement should have been:
(as usual, the ¦ is what you get when you press [alt/option]i )

At least that's where it's on my keyboard.
If you do know where it is on your keyboard, you're fine.

timster

2:30 pm on Sep 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Make sure to have BBEdit save that file with Unix line breaks before running Bjarne's commands.

(Basically, any time you use the Terminal, you'll need your files to have those Unix line breaks.)

mboydnv

5:10 pm on Sep 27, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



I love all of you! THANK YOU SO MUCH FOR THE HELP!

I was a little confused by the paths etc, then i figured it out. In the end I simply did exactly this:

cd /Users/mboyd/newfolders
cat /Users/mboyd/keywordtext ¦ xargs mkdir

The "pipe" character was made using shift -I <- which is just under the delete key on my keyboard.

Thanks again... If I may have one more question, how can i duplicate one index.html file into each of these 800 new folders?

=)

timster

9:04 pm on Sep 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's probably a quicker/more elegant way, but this should work.

1. Create a new file in bbedit with this content:

#!/bin/sh

cd ~/Desktop/newfolders
# cat ~/keywordtext ¦ xargs mkdir # Done already
# "#" at start of line means a comment, not code

for myDir in $(ls)
do cp ~/index.html ./$myDir/index.html
# Copies your file to each directory in turn
# Assumes the page you want is in your user directory,
# and is named "index.html"
done

2. Save it as "test.sh" in your main user directory.

3. Boot the Terminal

4. Enter: chmod +x test.sh
(Makes the file an executable script.)

5. Enter: ./test.sh
(Runs the script)

mboydnv

9:31 pm on Sep 27, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



WOW Timster! Thanks,

I'm confused by all the #... can you paste exactly what has to go in the text doc, and any comments outside of the paste. I'm just a beginner to this terminal stuff, so I can copy and paste in the terminal and obviously pick the correct directory for it to run etc, but am confused about these commands etc, so if you would be so kind to paste it like i need it - cheers

----- begin paste -----

code here

------end paste

--- comments about code...

mboydnv

10:36 pm on Sep 27, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



Timster! Thank you!

Nevermind my last stupid post, your instructions were perfect:

step 1: I created a BBedit doc saved with Unix breaks with the following:

--- paste --
#!/bin/sh

cd /Users/mboyd/twiggy/
for myDir in $(ls)
do cp /Users/mboyd/index/index.html ./$myDir/index.html
done
---- end paste ---

Twiggy was the name of the folder that had 800 folders all named with keywords inside it (/Users/mboyd/twiggy/). I saved test.sh loose in my home directory. (/Users/mboyd/test.sh)

I then launched terminal window and did the following:

1: cd /Users/mboyd/
2: chmod +x test.sh
3: ./test.sh

And voila 800 folders all with the same index.html inside it.

Thank you!

mboydnv

3:07 am on Sep 28, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



Ok I am back with one last task, lol, you guys have some great minds, I really appreciate you all helping out.

Here's my latest:

I have a text document with 800 keywords, and now I also have 800 folders on the hard drive all named with those keywords.

I am making my own site map. I would like to either do it in BBedit (using grep?) or maybe there is a way via terminal to take each keyword (from my text file) and link it using the same keyword as the title.

I would like to turn this (my text file filled with 800 keywords):

key-word1
key-word2
keyword3
keyword4
etc

into this (i don't mind using the same text file for saving)

<A HREF="http://www.mydomain.com/key-word1/">key-word1</A>
<A HREF="http://www.mydomain.com/key-word2/">key-word2</A>
<A HREF="http://www.mydomain.com/key-word3/">keyword3</A>
<A HREF="http://www.mydomain.com/key-word4/">keyword4</A>

is there a nice way to do that in BBedit? I'm not that savvy with it.

thanks! I appreciate it! This would complete my project. What a time saver you all have been. Much gratitude to you all.

timster

12:12 pm on Sep 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



All right, one more because you're right, you can do it with BBEdit's GREP.

Make a copy of your keywords file and open it.
Apple-F into the Find dialog box.
Click "Start at top" and "Use GREP"
Replace: (\S+)
With: <A HREF="http://www.mydomain.com/\1/">key-word1</A>
(Replace All)

This finds groups of non-whitespace ("\s" means whitespace and "\S" is the inverse of that, the "+" means match as many in a row as possible) and replace it with the string below.

The parentheses around the \S+ says "remember me" and the \1 says "paste the string you remembered here."

It's been a whirlwind tour of the Unix inside your Mac. You may want to pick up a good book on learning the Bash shell.

mboydnv

8:21 pm on Sep 28, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



I had to change it slightly cause I had 800 links all with the title being keyword1, so i added the \1

instead of:

Replace: (\S+)
With: <A HREF="http://www.mydomain.com/\1/">key_word1</A>

I did:

Replace: (\S+)
With: <A HREF="http://www.mydomain.com/\1/">\1</A>

This has been a great learning experience and I will be using this stuff over and over.

Thank you so much, You have been a great Help tim!

I hate to ask, but this would really be the icing on the cake...

would you know the grep to get rid of _ underscores in the anchor titles only? not in the anchors... replace all _ with (space) for every line after "> and capitalize first letter of every word in the title

for example
<A HREF="http://www.mydomain.com/las_vegas_gambling">Las Vegas Gambling</A>

Then I am absolutely done on this project and have no more requests! Again, thank you so much for caring enough to take the time to help me, this was really an important web project i had to do. I will look for more info on the net about grepping, seems like a great thiing to know...

all the best,

Michael

timster

12:43 pm on Sep 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Then I am absolutely done on this project and have no more requests!

Hey, anything to demonstrate the ease, elegance, and flexibiliy of a Mac!

The quick and dirty way to fix those anchors is this (with GREP on again)

In BBEdit, replace:

>(\w+)\_

With

>\1 

Repeat until the underscores are all replaced.

Now to add the capitals. Select find and make sure both the GREP and the Case Sensitive boxes are checked (and probably the "Start at Top" box too). Then replace:

>(.*)(\b[a-z])

with:

>\1\U\2

You'll have to repeat this a couple times too, as many times as the maximum number of words in an anchor.

mboydnv

10:00 pm on Oct 2, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thank you Tim!

I also used your example to make keywords in google ad words )inc url.

Thanks so much!