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


Click here to return to the 'Quickly remove resource forks' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Quickly remove resource forks
Authored by: bluehz on Jul 22, '03 10:06:14AM
This small script will remove the resource forks and retain the original names. USE WITH CAUTION - as with any automated rm commands - this one has the potention to wreak havoc. There is a test command you can use with it to display what WOULD be changed. Use the "-v" option - rm-rsrc . -v

#!/bin/sh

# Filename: rm-rsrc
# Remove resource forks
# Usage: rm-rsrc filename/dirname [-v]
#
# Single-file example:
#
#   rm-rsrc filename
#
# Complete contents of directory
#
#   cd <dir>
#   rm-rsrc .
#
# Test only - no files modified
#
#   rm -rsrc filename -v

for cfile in `ls $1`;
   do
   if [ $2 = "" ]; then
      cp $cfile $cfile.***tmp***
      mv $cfile.***tmp*** $cfile
   else if [ $2 = "-v" ]; then
      echo $cfile
   fi
   fi 
   done


[ Reply to This | # ]
don't use that shell script
Authored by: lukec on Jul 23, '03 02:25:02AM

A few suggestions.

Renaming a file to $name.*** is a bad idea. Unless you've somehow explicitly disabled command substitution this will likely not work. Type echo * in that same directory and see what you get. That will be substituted for '*'.

You should also look at replacing your 'ls' command with 'find . -type f'. This will enable recursive functionality.

You probably don't want to strip your resource forks in place. So using tar in a situation like this would be nothing short of brilliant. Straight from any non-apple manpage for tar:

tar -cf - -C srcdir . | tar xpf - -C destdir

I know we're all eager to share what we know, but you should always test a shell script before you post it. Those who would use it, probably can't debug it.

Luke



[ Reply to This | # ]
don't use that shell script
Authored by: bluehz on Jul 23, '03 07:21:56AM

thx for the info lukec - I am definitely no pro when it comes to scripting. Always open to input from those more skilled than me. Heck 80% of everything I have learned scripting has been from here.



[ Reply to This | # ]
don't use that shell script
Authored by: bluehz on Jul 23, '03 08:26:42AM

... also - I CHECK every script, hint, etc, I post - usually several times, and on more than one machine. The above script was tested, several times and performed acceptably for the purposes it was intended. It may not bethe best scripting in the world, BUT it does work, and I have had no problems with it.

...nevertheless thx



[ Reply to This | # ]