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 where 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::Dumper;
$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__
####
cpan> install Win32API::File
Win32API::File is up to date (0.1203).
cpan>
####
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
####
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 Application Data [C:\Users\tblaz\AppData\Roaming]
08/06/2019 02:22 AM Cookies [C:\Users\tblaz\AppData\Local\Microsoft\Windows\INetCookies]
08/06/2019 02:22 AM Local Settings [C:\Users\tblaz\AppData\Local]
08/06/2019 02:22 AM My Documents [C:\Users\tblaz\Documents]
...
08/06/2019 02:22 AM Start Menu [C:\Users\tblaz\AppData\Roaming\Microsoft\Windows\Start Menu]
08/06/2019 02:22 AM Templates [C:\Users\tblaz\AppData\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>