|
|
#1 |
|
All Star
Join Date: Jan 2002
Posts: 579
|
Finding files by creator code
Hello,
I'm trying to find all files with a certain creator code. I tried googling for a while and since I didn't come up with anything interesting, decided to try and script it. The problem I'm running into is one of quoting, the find I'm using to generate a list of files gets broken up at the space between files, for example it fails with "Address Book" or the like. I tried looking at find's man page and the only option similar was -X but it's not quite what I need. Any help is appreciated, here's the script: Code:
#!/bin/sh
# Find by creator from current dir
list=`find . -type f`
for file in $list
do
code=`GetFileInfo -c "${file}"`
if [ "$code" == "\"CODE\"" ]
then
echo $file
fi
done
exit 0
thanks, v Edit: Here's usage and errors: Code:
% touch file % touch "some file" % SetFile -c CODE file % SetFile -c CODE some\ file % ./script ./file GetFileInfo: could not refer to file (-43) file Last edited by vonleigh; 06-16-2003 at 07:53 PM. |
|
|
|
|
|
#2 |
|
Site Admin
Join Date: Jan 2002
Location: Montreal
Posts: 31,939
|
Perl version
The problem arises because the Bourne shell's lists are space-delimited. I don't know how to avoid this problem in the Bourne shell.
But here's a Perl version that works: Code:
#!/usr/bin/perl -w
die "Must supply creator code as argument\n" unless $ARGV[0];
my $target = $ARGV[0]; # creator code to be looked for
$target = "\"$target\""; # add quotes before and after code
my @list = `find . -type f`;
foreach my $file (@list)
{
chomp($file);
my $code = `/Developer/Tools/GetFileInfo -c "$file"`;
chomp($code);
if ($code eq $target)
{
print "$file\n";
}
}
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|