source: test-collections/trunk/filename-encodings/bin/script/dirlist.pl@ 23464

Last change on this file since 23464 was 23464, checked in by davidb, 13 years ago

Further debugging output for working with Windows files

File size: 1.2 KB
RevLine 
[23325]1#!/usr/bin/perl -w
2
3
[23464]4use Encode;
[23346]5
[23325]6sub debug_unicode_string
7{
8 join("",
9 map { $_ > 128 ? # if wide character...
10 sprintf("\\x{%04X}", $_) : # \x{...}
11 chr($_)
12 } unpack("U*", $_[0])); # unpack Unicode characters
13}
14
15
16if (scalar(@ARGV)!=1) {
17 my $prog_name = $0;
18 $prog_name =~ s/^.*(\\|\/)//;
19
20 print STDERR "Usage: $prog_name dir\n";
21 exit(1);
22}
23
24my $dir = $ARGV[0];
25
26opendir(DIN,"$dir")
27 || die "Unable to open $dir";
28
29my @files = grep { $_ !~ m/^\./ } readdir(DIN);
30
31close(DIN);
32
33foreach my $f (@files)
34{
35 print "Filename as is: $f\n";
36 print "Filename debug: ", debug_unicode_string($f),"\n";
37
38 my $dirsep = ($^O =~ /mswin/i) ? "\\" : "/";
39
[23346]40 $f =~ s@$dirsep$@@;
[23325]41
[23464]42 my $full_f = "$dir$dirsep$f";
43 if ($^O =~ /mswin/i) {
44 require Win32;
45 $full_f = Win32::GetLongPathName($full_f);
46 #$full_f = encode("UTF8",$full_f);
47 print "Windows full filename: ", $full_f,"\n";
48 print "Windows full filename debug: ", debug_unicode_string($full_f),"\n";
49
50 $full_f = Win32::GetShortPathName($full_f);
[23325]51 }
[23464]52
53 if ( -e $full_f ) {
54 print " Perl can see file $full_f\n";
55 }
[23325]56 else {
[23464]57 print " Perl CANNOT see $full_f\n";
[23325]58 }
59}
60
[23464]61
Note: See TracBrowser for help on using the repository browser.