Here's some sample code I have. It has separate code for files and
folders, and can get the flags for invisibility, and set them.
The basic code is this:
#!perl -w
use Mac::Files;
use strict;
use constant fInvisible => 16384;
my $file = $ARGV[0];
my $info = FSpGetFInfo($file) or die $^E;
my $flags = $info->fdFlags;
# make visible
$flags ^= fInvisible if $flags & fInvisible;
#make invisible
#$flags |= fInvisible unless $flags & fInvisible;
$info->fdFlags($flags);
FSpSetFileInfo($file, $info);
__END__
The more complete sample code and routines are below.
#!perl -w
use Mac::Files;
use strict;
use constant fInvisible => 16384;
for (@ARGV) {
if (-l) {
next;
} elsif (-f) {
change_file($_);
} elsif (-d) {
change_dir($_);
}
}
exit;
sub change_file { # switch file between visible / invisible
my($file, $flags, $info) = @_;
$flags = get_fflags($file);
set_fflags($file, is_visible($flags) ?
make_invisible($flags) : make_visible($flags));
}
sub change_dir { # switch dir between visible / invisible
my($dir, $flags, $info) = @_;
$flags = get_dflags($dir);
set_dflags($dir, is_visible($flags) ?
make_invisible($flags) : make_visible($flags));
}
sub get_fflags { # get file flags
my $info = FSpGetFInfo($_[0]) or die "Can't get flags for $_[0]: $^E";
$info->fdFlags;
}
sub get_dflags { # get dir flags
my $info = FSpGetCatInfo($_[0]) or die "Can't get flags for $_[0]: $^E";
$info->ioDrUsrWds->frFlags;
}
sub set_fflags { # set file flags
my($file, $flags, $info) = @_;
$info = FSpGetFInfo($file) or die "Can't get flags for $file: $^E";
$info->fdFlags($flags);
FSpSetFInfo($file, $info) or die "Can't set flags for $file: $^E";
}
sub set_dflags { # set dir flags
my($dir, $flags, $info, $d_info) = @_;
$info = FSpGetCatInfo($dir) or die "Can't get flags for $dir: $^E";
$d_info = $info->ioDrUsrWds;
$d_info->frFlags($flags);
$info->ioDrUsrWds($d_info);
FSpSetCatInfo($dir, $info) or die "Can't set flags for $dir: $^E";
}
# is item invisible?
sub is_visible {return ((shift() & fInvisible) ? 0 : 1)}
sub make_visible { # make flags visible
my $flags = shift;
return (($flags & fInvisible) ? $flags ^ fInvisible : 0)
}
sub make_invisible { # make flags invisible
my $flags = shift;
return (($flags & fInvisible) ? 0 : $flags | fInvisible)
}
__END__
--
Chris Nandor [EMAIL PROTECTED] http://pudge.net/
Open Source Development Network [EMAIL PROTECTED] http://osdn.com/