i have a bunch of .rar files from those great music blogs. unrar on freebsd, afaik (from help and man), does not create a directory but merely spews all the files out wherever you desire.

what i want to be able to do is:

1. create two directories - one in my mp3 player and the other on my hard drive - base on the *.rar name, i.e. if i have /hd/foo.rar i want to mkdir /mp3/foo and /hd/foo . typically the *.rar names include only spaces as for special characters.2. unrar e /hd/foo.rar /hd/foo/ (note if the file demands a password, i imagine the script would break or halt. it would be helpful to know which file causes it.)3. cp -R /hd/foo/*mp3 /mp3/foo/4. repeat 1-3 for the rest of the *.rar files

also this isn't necessary to the script, but i am wondering if i missed an option in the man for cp, as it is quite an annoyance to have to make the destination directory by mkdir foo rather than just having a cp option to use the same dir name and make one in the destination.

This is a quickie and I'm not 100% certain this will work, as I don't have any rar files to work with. I did create a text file named "foo off.rar" because it had a space in it, and everything seemed to work and you should be able to edit it to your needs.

Code:

#! /bin/sh

#"foo oof.rar" is my example file

# let's record our current location so we can come back hereorigin=$(pwd)

# for everything named *.rarfor line in *.rar

# everything from "do" to "done" will be performed on every rar filedo

# basename will take a path and give you the file name. # if you know the file extension, add it to the end of the command # and basename will chop it off in it's output

# this is running the command: basename "foo oof.rar" .rar# the output should be "foo oof"name=$(basename "$line" .rar)

# I'm not sure you want to do it this way, # you may want to edit the next 5 lines# but it should give you some ideas on ways to do it

# create directory "foo oof"mkdir "$name"

# move "foo oof.rar" into itmv "$line" "$name"

# cd into it cd "$name"

# unrar "foo oof.rar""unrar e $line"

# make directory /mp3/"foo oof"/ and copy all mp3s to it mkdir /mp3/"$name"/cp *.mp3 /mp3/"$name"/

# go back to the original location so we're in the #right place to run all this again on the next rarcd "$origin"

This is a quickie and I'm not 100% certain this will work, as I don't have any rar files to work with. I did create a text file named "foo off.rar" because it had a space in it, and everything seemed to work and you should be able to edit it to your needs.

Code:

#! /bin/sh

#"foo oof.rar" is my example file

# let's record our current location so we can come back hereorigin=$(pwd)

# for everything named *.rarfor line in *.rar

# everything from "do" to "done" will be performed on every rar filedo

# basename will take a path and give you the file name. # if you know the file extension, add it to the end of the command # and basename will chop it off in it's output

# this is running the command: basename "foo oof.rar" .rar# the output should be "foo oof"name=$(basename "$line" .rar)

# I'm not sure you want to do it this way, # you may want to edit the next 5 lines# but it should give you some ideas on ways to do it

# create directory "foo oof"mkdir "$name"

# move "foo oof.rar" into itmv "$line" "$name"

# cd into it cd "$name"

# unrar "foo oof.rar""unrar e $line"

# make directory /mp3/"foo oof"/ and copy all mp3s to it mkdir /mp3/"$name"/cp *.mp3 /mp3/"$name"/

# go back to the original location so we're in the #right place to run all this again on the next rarcd "$origin"

done

Hi this script looks promising but I doubt it will work with split archives such as archive.part01.rar, part02 etc. or the old naming convention archive.r01 etc. Is there a way that you can assist with this? "To make it read or find that .r01 or part01.rar.

I already asked this somewhere but I think we already have a foundation here so I thought of a follow up question.

What if I just want to rar each ISO files inside a folder?

Code:

# Our own standard (this is very possibly the same as one of the above, but since there's more then 1 option it's better to recreate it) outfile="$inpath/repacked/$relname.rar"; cd $inpath/repacked; # Pack the files into 200Mb files (-v200000k is for 200Mb noted in Kb) rar a -m0 -r -v200000k $outfile *; # If it succeds we move the files around to the right place if [ $? -eq 0 ]; then outpath="$inpath/repacked"; mv $outpath/* $inpath; # Delete the temporary "repacked" directory rm -rf $outpath; else echo "Failed to compress files... exiting..."; fi else echo "Failed to extract files ($relname).. exiting"; fifi# Return to where you started when executing the script.cd $oldpwd

Who is online

Users browsing this forum: Yahoo [Bot] and 9 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum