in reply to How to get filesystem ownerships

#!/usr/bin/perl -w use strict; $| =1; my $path = 'C:\temp'; my @lines = `"dir /Q $path"`; foreach my $line (@lines) { next unless $line =~ m|^\d+/\d+|; my ($owner, $file) = ($line =~ /\\(\w+)\s+(.*)$/)[0,1]; print "$owner\t $file\n"; } __END__ prints: Marshall trace.pl Marshall trace.txt Marshall transpose.pl Marshall transpose1.pl ...etc...

Replies are listed 'Best First'.
Re^2: How to get filesystem ownerships
by Anonymous Monk on Apr 22, 2010 at 18:40 UTC
    Argh windows perl drives me batty ..this is the output that gives me..thanks for the help though!!
    C:\temp>perl cifsplit.pl Administrators . Use of uninitialized value $owner in concatenation (.) or string at ci +fsplit.pl line 12. Use of uninitialized value $file in concatenation (.) or string at cif +split.pl l ine 12. Use of uninitialized value $owner in concatenation (.) or string at ci +fsplit.pl line 12. Use of uninitialized value $file in concatenation (.) or string at cif +split.pl l ine 12. Administrators rgreceiverInstaller.log
      Sounds like the problem lies in this regex:
      my ($owner, $file) = ($line =~ /\\(\w+)\s+(.*)$/)[0,1];
      I get Machine\User for dir /Q.
      VIPER\Marshall   Some filename with spaces.txt

      do a "dir /Q" from command line and post result here and the regex can be tweaked and yes it can be frustrating.

        C:\>dir /Q Volume in drive C has no label. Volume Serial Number is C4F5-E00C Directory of C:\ 04/22/2010 03:50 PM <DIR> BUILTIN\Administrators Apps 09/18/2006 04:43 PM 24 BUILTIN\Administrators autoexec +.bat 01/20/2008 09:24 PM 333,203 NT SERVICE\TrustedInstabootmgr 09/18/2006 04:43 PM 10 BUILTIN\Administrators config.s +ys 12/02/2008 02:34 PM <DIR> NT AUTHORITY\SYSTEM HPACC 12/02/2008 02:45 PM <DIR> NT AUTHORITY\SYSTEM Logs 12/02/2008 02:34 PM <DIR> NT AUTHORITY\SYSTEM MSDERelA 12/02/2008 02:34 PM <DIR> NT AUTHORITY\SYSTEM Oracle 01/20/2008 09:32 PM <DIR> ... PerfLogs 04/12/2010 12:35 PM <DIR> NT AUTHORITY\SYSTEM Perl 03/28/2010 05:20 PM <DIR> NT SERVICE\TrustedInstaProgram +Files 12/02/2008 02:34 PM <DIR> NT AUTHORITY\SYSTEM Sun 04/22/2010 03:41 PM <DIR> BUILTIN\Administrators temp 01/25/2010 10:52 AM <DIR> BUILTIN\Administrators Users 03/23/2010 08:36 AM <DIR> NT SERVICE\TrustedInstaWindows 05/04/2007 08:41 AM 150 BUILTIN\Administrators YServer. +txt
        Thanks again!!!!!