Forum Moderators: travelin cat

Message Too Old, No Replies

Files are named after Directory names

Folder name batching again

         

mboydnv

7:35 am on Dec 28, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



what's syntax (via command terminal) to take 1800 all unique directory names and name the file inside of each directory the name of the directory.

Here's what i have..

Directory name / index.html
Directory name 2 / index.html

i would like to name the file inside each directory the name of the directory...

Directory name / Directory name <-----.html file is renamed what the dirctory is named

Directory name 2/ Directory name 2 <-----.html file is renamed what the dirctory is named

I need to do this for 1800 files

Any ideas? Timster you there by chance?

Thank you so much!

BjarneDM

12:44 am on Jan 2, 2005 (gmt 0)

10+ Year Member



ls ¦ xargs -I % -R 3 mv %/index.html %/%.html

should do it if you've only got folders an no files in the containing directory; otherwise it gets a little more complicated:

find . -type d -maxdepth 1 ¦ 
sed -e 's/\.\///' -e '/^\./d' ¦
xargs -I % -R 3 mv %/index.html %/%.html

all on one line

mboydnv

1:39 am on Jan 2, 2005 (gmt 0)

10+ Year Member Top Contributors Of The Month



thank you!

Would it be easier if we did this?

Start with a text document of all the file names:

meeting0861.htm
meeting0862.htm

etc

I have 2,000 of these files and can copy the names into a Text document easily. What i want to do is duplicate a new doorway page i call it new.html And i want to duplicate this new.html file 2000 times with each duplicate being named after what is in the text document.

so new.html duplicates and is named meeting0861.htm
new.html is duplicated again and named meeting0862.html

Thank you so much

PS: Bjarne you helped me out beforeand many thanks in an awesome thread that Timster jumped in on too... I'm doing a variation of that

[webmasterworld.com...]

instead of folder would love files..

here's the old post --------

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!

BjarneDM

10:45 am on Jan 2, 2005 (gmt 0)

10+ Year Member



It's easy enough to duplicate a single file into a lot of names when you've got them listed in a file:

cat <file> ¦ xargs -I % -R 1 cp new.html %.html

Question is: do you also want these files placed into individual folders?

Look, the man pages are your friend in these cases, and even though they at first can seem a bit overwhelming you ought to be able to 'decode' them with the example solution given here.

For an introduction to the tchs shell in general look here:
[osxfaq.com...]
[macdevcenter.com...]
[macdevcenter.com...]

For very good books on Mac OS X Terminal you've got these ones:
[oreilly.com...]
[oreilly.com...]
[oreilly.com...]
[oreilly.com...]

By the way, if you've gotten that many files with a common theme you might be much better off by looking into how PHP could help you. I'm using the technique described on this page : [sitepoint.com...] to administer the content of my sites. This means, that I've got a template and then load the necessary individual pieces into this page. Thus, a sitewide update of the look-and-feel only has to be done in one place.

mboydnv

9:36 pm on Jan 2, 2005 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thank you very much! That worked perfectly! And thanks for the tips!