"We are back" « oc.at

Charset Problem mit Perl Globbing auf Windows mit BSD_glob() *solved*

GrandAdmiralThrawn 09.10.2014 - 10:22 3841 17
Posts

GrandAdmiralThrawn

Lord of Derailment
Avatar
Registered: Aug 2000
Location: BRUCK!
Posts: 3807
z.B. in Win32::Unicode::Dir.

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::Dir 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?
Bearbeitet von GrandAdmiralThrawn am 10.10.2014, 15:32

GrandAdmiralThrawn

Lord of Derailment
Avatar
Registered: Aug 2000
Location: BRUCK!
Posts: 3807
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:

Code: PERL
use 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.
  }
}
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.

Danke jedenfalls für die Inspiration, es hat geholfen!

Man muß einfach echt in jedem einzelnen Schritt in der Verarbeitungskette sicherstellen, daß Unicode verstanden wird.
Bearbeitet von GrandAdmiralThrawn am 10.10.2014, 18:56

GrandAdmiralThrawn

Lord of Derailment
Avatar
Registered: Aug 2000
Location: BRUCK!
Posts: 3807
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: PERL
use 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.
  }
}
Kontakt | Unser Forum | Über overclockers.at | Impressum | Datenschutz