#! c:\perl\bin\perl.exe #------------------------------------------------ # mac.pl # # Retrieve MAC times from files on NT/2K # # usage: [perl] mac.pl [options] # # Requires Win32::Perms # http://www.roth.net/perl/perms # Copyright 2000/2001 H. Carvey keydet89@yahoo.com #------------------------------------------------ use strict; use Win32::Perms; use Getopt::Long; Win32::Perms::LookupDC(0); my %config = (); Getopt::Long::Configure("prefix_pattern=(-|\/)"); GetOptions(\%config, qw(dir|d=s sub|s help|?|h)); \usage(); exit 0 if (!%config || $config{help}); my $dir = $config{dir} || Win32::GetCwd; print "Start search,".time.",".localtime(time)."\n"; print "File,Size,Last Access,Last Modification,Creation\n"; \&Search($dir); print "Search complete,".time.",".localtime(time)."\n"; sub Search { my $dir = $_[0]; if (opendir(FH,$dir)) { my (@dirs,@files); while (my $file = readdir(FH)) { next if ($file eq "." || $file eq ".."); my $path = "$dir\\$file"; push (@dirs,$path) if (-d $path); push (@files,$path) if (-f $path); } closedir(FH); foreach my $file (@files) { \macdaddy($file); } if ($config{sub}) { foreach my $path (@dirs) { \&Search($path); } } } } sub macdaddy { my $file = $_[0]; my $owner = ""; my ($size,$atime,$mtime,$ctime) = (stat($file))[7..10]; my $a_time = localtime($atime); my $m_time = localtime($mtime); my $c_time = localtime($ctime); eval { my $perms = new Win32::Perms($file); $owner = $perms->Owner(); }; print "$file,$size,$owner,$a_time,$m_time,$c_time\n"; } sub usage { print STDERR "\nMAC.pl\n"; print STDERR "Collect MAC times and owner from files in a directory.\n"; print STDERR "\nUsage: [perl] mac.pl [-d dir] [-s] [-h/?] [> myfile.csv]\n"; print STDERR " -d Directory to search. May be a mapped dir, or UNC path\n"; print STDERR " (default: current working directory)\n"; print STDERR " -s Check subdirectories\n\n"; print STDERR "By default, search starts at current dir, looking at all files.\n"; print STDERR "NOTE: Beginning and end of search are timestamped. Output is in CSV format\n"; print STDERR " for easy opening in Excel.\n\n"; print STDERR "Copyright 2000/2001 H. Carvey keydet89\@yahoo.com.\n"; }