M
Mitrokhin
Hello
(First off this is my first python (semi-) script so bear with me .
What is the most efficient way to walk a directory structure and
list files with resource forks ?. Reusing bits of code from here and
there the script below is what I've come up with, but can't it be
done in a better and quicker way ?
import os, os.path
for dir, subdir, files in os.walk(os.getcwd()):
for file in files:
temp = os.path.join(dir,file,'..namedfork', 'rsrc')
if os.path.isfile(temp) and os.path.getsize(temp) > 0:
print os.path.join(dir,file)
By comparison the perl script below (which needless to say isn't of my
creation) seems lightningly fast.
Also (dare I ask for this too) If some nice soul could point me in the
right direction for picking up files with extended attributes under OS
X I'd be really gratefull to. Should it be done the same way, ie. via
os. calls or perhaps by way of a popen or ... ?
Suggestions anyone
============
#!/usr/bin/perl -w
# Perl script to find files with Mac resource forks. Files are found
# recursively from the specified directory.
use strict;
use File::Find ();
if ($#ARGV != 0) {
print "Usage: $0 <directory>\n";
exit(-1);
}
my $rootDir = $ARGV[0];
use vars qw/*name/;
*name = *File::Find::name;
#File::Find::find({wanted => \&checkForResourceFork, no_chdir =>0,
File::Find::find({wanted => \&checkForResourceFork, no_chdir =>1,
follow=>1}, $rootDir);
sub checkForResourceFork {
my $rsrcNamePath = "$name/..namedfork/rsrc";
if ((-e $rsrcNamePath) && ((-s "$name/..namedfork/rsrc") > 0)) {
print "$name\n";
}
}
============
(First off this is my first python (semi-) script so bear with me .
What is the most efficient way to walk a directory structure and
list files with resource forks ?. Reusing bits of code from here and
there the script below is what I've come up with, but can't it be
done in a better and quicker way ?
import os, os.path
for dir, subdir, files in os.walk(os.getcwd()):
for file in files:
temp = os.path.join(dir,file,'..namedfork', 'rsrc')
if os.path.isfile(temp) and os.path.getsize(temp) > 0:
print os.path.join(dir,file)
By comparison the perl script below (which needless to say isn't of my
creation) seems lightningly fast.
Also (dare I ask for this too) If some nice soul could point me in the
right direction for picking up files with extended attributes under OS
X I'd be really gratefull to. Should it be done the same way, ie. via
os. calls or perhaps by way of a popen or ... ?
Suggestions anyone
============
#!/usr/bin/perl -w
# Perl script to find files with Mac resource forks. Files are found
# recursively from the specified directory.
use strict;
use File::Find ();
if ($#ARGV != 0) {
print "Usage: $0 <directory>\n";
exit(-1);
}
my $rootDir = $ARGV[0];
use vars qw/*name/;
*name = *File::Find::name;
#File::Find::find({wanted => \&checkForResourceFork, no_chdir =>0,
File::Find::find({wanted => \&checkForResourceFork, no_chdir =>1,
follow=>1}, $rootDir);
sub checkForResourceFork {
my $rsrcNamePath = "$name/..namedfork/rsrc";
if ((-e $rsrcNamePath) && ((-s "$name/..namedfork/rsrc") > 0)) {
print "$name\n";
}
}
============