URL: https://www.overclockers.at/coding-stuff/charset-problem-mit-perl-globbing-auf-windows-mit-bsd_glob-solved_240648/page_2 - zur Vollversion wechseln!
z.B. in Win32::Unicode:ir.
Leider gibts das Modul ned für mein geliebtes ActivePerl. Also probier ich halt jetzt echt Mal Strawberry Perl aus. Verdammt noch Mal!!
Edit: Ok, eh liab. Nur Strawberry hat keine Binary Module, da is ein kompletter GCC dabei. Wennst ein Modul installieren willst, saugt er den Quellcode und versuchts lokal zu kompilieren. Der Versuch Win32::Unicode:ir zu kompilieren ist natürlich kapital failed, wie so oft wenn man irgendwas irgedwo von Source bauen will.
Edit 2: "W i n 3 2 : : U n i c o d e : : D i r"! Kann man hier irgendwie den Smilieparser abdrehn?
Ok, es ist geschafft, Gott sei Dank. Hab die failing Tests beim Kompilieren der Unicode Module Mal elegant ignoriert ("force install" *hust*)... Damit habe ich jetzt Win32::Unicode und Win32::Unicode::-Dir. Außerdem das damit nun auch benötigte Win32API::File::Time, weil File::Stat mit Unicode nicht kann. Dirchecks sind keine mehr drin, weil die gegebene Funktion sowieso sicherstellt, daß nur Ordner und keine Dateien gelistet werden können. Macht's einfacher.
Wieder ein bissl (zusammengeschnittener) Code:
Halleluja! Und den ganzen Output man dann auch noch easy in ein File stopfen, das man am besten per open(FILEHANDLE, ">:encoding(UTF-8)", $filename); öffnen sollte, da UTF-8 scheinbar als Superset von UCS-2le und ISO-8859-15 gelten darf.Code: PERLuse strict; # Strict code only, no dodgy stuff. use Win32::Unicode::-Dir; # Windows UCS-2le Unicode directory functions (THE DASH IS AGAINST SMILEY PARSING ON oc.at!) use Win32API::File::Time "GetFileTime"; # Windows UCS-2le Unicode timestamp function. my $basepath = "E:/Data"; my @tree = dir_list $basepath; # Read folders on level 2 into array ("E:/Data" is considered level 1, "E:" level 0). my $branch = ""; my @leaves = (); my $leaf = ""; my $atime = ""; my $mtime = ""; my $ctime = ""; my %mtimestamps = (); my $leafcount = 0; for (@tree) { $_ = $basepath . "/" . $_; } # Expanding array values to full path names. foreach $branch (@tree) { # Iterate through folder level 2. @leaves = dir_list $branch; # Listing folders on level 3. for (@leaves) { $_ = $month . "/" . $_; } # Expanding array values to full path names. foreach $leaf (@leaves) { # Iterate through folders on Level 3. ($atime, $mtime, $ctime) = GetFileTime($leaf); # Getting timestamps. $mtimestamps{$leaf} = $mtime; # Add mod. timestamp as a value to the hashtable for the current folder name as key. $leafcount++; # Increment total folder count. } }
Verdammt noch Mal, geht auch nicht. Sieht auf'n ersten Blick so aus, ist aber nicht so. Stat Calls failen still und heimlich auf non-ASCII Chars und liefern nichts als Ergebnis zurück, Fehler hab ich keinen abgefangen. Schuld ist natürlich die Implementierung in Win32API::File::Time. Also gut, dann nehmen wir eben Win32::Unicode::File, dann passts auch wirklich (man beachte den sprechenden Funktionsnamen bei statW(), den ich jetzt auch gleich verstehe ):
Code: PERLuse strict; # Strict code only, no dodgy stuff. use Win32::Unicode::-Dir; # Windows UCS-2le Unicode directory functions (THE DASH IS # AGAINST SMILEY PARSING ON oc.at!) use Win32::Unicode::File; # Windows UCS-2le Unicode file & dir functions. my $basepath = "E:/Data"; my @tree = dir_list $basepath; # Read folders on level 2 into array ("E:/Data" is # considered level 1, "E:" level 0). my $branch = ""; my @leaves = (); my $leaf = ""; my @mtime = (); # Array for file meta data. statW() will return the modification # time stamp as element #9. my %mtimestamps = (); my $leafcount = 0; for (@tree) { $_ = $basepath . "/" . $_; } # Expanding array values to full path # names. foreach $branch (@tree) { # Iterate through folder level 2. @leaves = dir_list $branch; # Listing folders on level 3. for (@leaves) { $_ = $month . "/" . $_; } # Expanding array values to full path # names. foreach $leaf (@leaves) { # Iterate through folders on Level 3. @mtime = statW($leaf); # Getting timestamp. $mtimestamps{$leaf} = @mtime[9]; # Add modification timestamp as a value to the # hashtable for the current folder name as key. $leafcount++; # Increment total folder count. } }
overclockers.at v4.thecommunity
© all rights reserved by overclockers.at 2000-2025