Thanks for your pithy reply, pryrt. I wish my reply could be so concise, but I'm still grabbing at straws. I try to save the vertical space for responders so will put the rest of what I have that pertains between readmore tags:
With a couple lines of your script commented out, I'm getting good preliminary results:
C:/Users/tblaz/1.modules.pl C:/Users/tblaz/1.txt C:/Users/tblaz/2.txt $VAR1 = { 'Start Menu' => 1, 'Application Data' => 1, 'My Documents' => 1, 'Cookies' => 1, 'Local Settings' => 1, 'Templates' => 1, 'Recent' => 1, 'NetHood' => 1, 'PrintHood' => 1, 'SendTo' => 1 }; d C:/Users/tblaz/3D Objects C:/Users/tblaz/5.txt d C:/Users/tblaz/AppData Jd C:/Users/tblaz/Application Data d C:/Users/tblaz/Contacts Jd C:/Users/tblaz/Cookies d C:/Users/tblaz/Desktop d C:/Users/tblaz/Documents ... Jd C:/Users/tblaz/Start Menu Jd C:/Users/tblaz/Templates d C:/Users/tblaz/Videos $VAR1 = {}; d C:/Strawberry/c d C:/Strawberry/cpan C:/Strawberry/DISTRIBUTIONS.txt d C:/Strawberry/licenses d C:/Strawberry/perl C:/Strawberry/README.txt C:/Strawberry/relocation.txt d C:/Strawberry/win32
#!/usr/bin/perl -w use 5.011; ## inspired by https://perlmonks.org/?node_id=1223819 ## my old link to a junction post => https://perlmonks.org/?node_ +id=1178059 ## found https://github.com/dagolden/Path-Tiny/issues/160 (which is wh +ere these functions came from) ## added the -d and -l tests use Path::Tiny; use Win32API::File qw'GetFileAttributes :FILE_ATTRIBUTE_'; for my $p (glob('C:/Users/tblaz/*'), glob('C:/Strawberry/*') ) { print is_junction($p) ? "J" : " "; print -d($p) ? "d" : " "; print -l($p) ? "l" : " "; #print f32attr($p); #print isjunc($p) ? " j " : " "; print " $p\n" } sub is_junction { my ($dir) = @_; state $last_parent; state $junction_by; my $path = path($dir); if (! $path->is_dir || $path->is_rootdir) { return 0; } if (! defined $last_parent || $path->parent ne $last_parent) { $junction_by = { map { $_ => 1 } list_junctions($path->parent) + }; use Data::Dumper; print Dumper $junction_by; no Data::Dump +er; $last_parent = $path->parent; } return exists $junction_by->{$path->basename}; } sub list_junctions { my ($dir) = @_; my $path = path($dir); if (! $path->is_dir) { return (); } my $cmd = sprintf 'dir /AL /B "%s" 2>&1', $path->canonpath; my @lines = `$cmd`; chomp @lines; if ($? >> 8) { if ($lines[0] eq 'File Not Found') { return (); } else { die "Failed to execute: $cmd"; } } return @lines; } __END__
You post code for the functions I commented out. Where is that supposed to go? I have:
cpan> install Win32API::File Win32API::File is up to date (0.1203). cpan>
My module-finding script works despite the complaints to STDOUT, showing a few different places where they end up. I could hardly believe how many matches I got from File.pm:
C:/Strawberry/cpan/build/LWP-Online-1.08-0/inc/Module/Install/Makefile +.pm Makefile.pm access age in days: 8.24 ... C:/Strawberry/perl/lib/Win32API/File.pm File.pm access age in days: 8.25 ... C:/Strawberry/perl/vendor/lib/Win32/File.pm File.pm access age in days: 8.25
Now for the questions.
Q1 Where does the code for the is_junc and f32attr subs go?
Q2 Am I correct to surmise that File::Find is essentially broken for windows? (Others may say windows is broken without the point being different.)
With this coming from the terminal:
C:\Users\tblaz>dir /AL Volume in drive C is Windows Volume Serial Number is ECCC-9917 Directory of C:\Users\tblaz 08/06/2019 02:22 AM <JUNCTION> Application Data [C:\Users\tbla +z\AppData\Roaming] 08/06/2019 02:22 AM <JUNCTION> Cookies [C:\Users\tblaz\AppData +\Local\Microsoft\Windows\INetCookies] 08/06/2019 02:22 AM <JUNCTION> Local Settings [C:\Users\tblaz\ +AppData\Local] 08/06/2019 02:22 AM <JUNCTION> My Documents [C:\Users\tblaz\Do +cuments] ... 08/06/2019 02:22 AM <JUNCTION> Start Menu [C:\Users\tblaz\AppD +ata\Roaming\Microsoft\Windows\Start Menu] 08/06/2019 02:22 AM <JUNCTION> Templates [C:\Users\tblaz\AppDa +ta\Roaming\Microsoft\Windows\Templates] 0 File(s) 0 bytes 10 Dir(s) 459,449,827,328 bytes free C:\Users\tblaz>dir /AL /B Application Data Cookies Local Settings My Documents NetHood PrintHood Recent SendTo Start Menu Templates C:\Users\tblaz>dir /AL /B My* My Documents C:\Users\tblaz>
Q3) What is the simplest way to test whether a file is a junction, and if it is, simply ignore it whilst recursing through the rest of them?
Thanks for your comment
In reply to Re^2: getting a few simple scripts to work on windows
by Aldebaran
in thread getting a few simple scripts to work on windows
by Aldebaran
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |