Schrift
[thread]7206[/thread]

DosGlob & Verzeichnisse mit Leerzeichen

Leser: 1


<< |< 1 2 >| >> 11 Einträge, 2 Seiten
pktm
 2005-08-13 03:13
#57166 #57166
User since
2003-08-07
2921 Artikel
BenutzerIn
[Homepage]
user image
Hallo!

Kann das sein, dass File::DosGlob Probleme mit Verzeinisnamen hat die Leerzeichen enthalten?
Gibt es da eine Lösung zu (nein ich werde nicht die Verzeichnisse umbenennen :-) )?

Hier mein
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/Perl/bin/perl

use strict;
use Data::Dumper;
use File::DosGlob;

my $dir = "C:/Dokumente und Einstellungen/pktm/*.*";
my $dir2 = "C:/*.*";
my @r = File::DosGlob::glob($dir);
print Data::Dumper::Dumper( \@r );
# Ausgabe: $VAR1 = [];

@r = File::DosGlob::glob($dir2);
print Data::Dumper::Dumper( \@r );
# Ausgabe = alle Dateien auf der Ebene


Grüße, Alex
http://www.intergastro-service.de (mein erstes CMS :) )
J-jayz-Z
 2005-08-13 03:26
#57167 #57167
User since
2005-04-13
625 Artikel
BenutzerIn
[Homepage] [default_avatar]
Ich weiß nicht, ob dir das weiter hilft, aber unter *nix müssen Leerzeichen im Dateinamen escaped werden. Etwa so:
Code: (dl )
/home/user/datei\ name\ mit\ leerzeichen
perl -Mstrict -Mwarnings -e 'package blub; sub new { bless {} } sub bar {my $self=shift; $self->{bla}="5065726c2d436f6d6d756e697479"; return $self->{bla};} my $foo=blub->new();print "Hallo ";print pack("H*",$foo->bar()); print "\n"'

http://perl-tutor.de
pktm
 2005-08-13 03:43
#57168 #57168
User since
2003-08-07
2921 Artikel
BenutzerIn
[Homepage]
user image
Das bringt leider keine Änderung (sitez halt an einem Win32-System).
Hier mal ein ausführlicherer Testcode (jetzt wisst ihr, woher das Gerücht kommt, dass Perl unleserlich wäre :-D ):
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/Perl/bin/perl

use strict;
use Data::Dumper;
use File::Spec;
use File::DosGlob;

print "Version: " . $File::DosGlob::VERSION . "\n";

print "dir with spaces, Win32-OS (XP home), unix-slash-notation\n";
my $dir = "C:/Dokumente und Einstellungen/pktm/*.*";
print "dir: $dir \n";
my @r = File::DosGlob::glob($dir);
print "output:\n";
print Data::Dumper::Dumper( \@r );

print "\nnext: dir without spaces\n";
my $dir2 = "C:/*.*";
print "dir: $dir2 \n";
@r = File::DosGlob::glob($dir2);
print "output:\n";
print Data::Dumper::Dumper( \@r );

print "\nnext: dir with spaces and File::Spec\n";
my $dir3 = File::Spec->catfile("C:/Dokumente und Einstellungen/pktm/", '*.*');
print "dir: $dir3 \n";
@r = File::DosGlob::glob($dir3);
print "output:\n";
print Data::Dumper::Dumper( \@r );

# Vollständiger Output:
#Use of uninitialized value in substr at C:/Perl/lib/File/DosGlob.pm line 38.
#Version: 1.00
#dir with spaces, Win32-OS (XP home), unix-slash-notation
#dir: C:/Dokumente und Einstellungen/pktm/*.*
#output:
#$VAR1 = [];
#
#next: dir without spaces
#dir: C:/*.*
#
#output:
#$VAR1 = [
#          'C:/.cpan',
# ...lots of files...
#        ];
#
#next: dir with spaces and File::Spec
#dir: C:\Dokumente und Einstellungen\pktm\*.*
#output:
#$VAR1 = [];
\n\n

<!--EDIT|pktm|1123890268-->
http://www.intergastro-service.de (mein erstes CMS :) )
renee
 2005-08-13 15:28
#57169 #57169
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Mach's mit opendir,readdir und closedir...

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/perl

use strict;
use warnings;

my $dir = 'C:\Dokumente und Einstellungen\pktm';

opendir(DIR,$dir) or die $!;
my @files = map{$dir.'\'.$_}grep{-f $_ && $_ =~ /\./}readdir(DIR);
closedir DIR;

print $_,"\n" for(@files);
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
pktm
 2005-08-13 19:02
#57170 #57170
User since
2003-08-07
2921 Artikel
BenutzerIn
[Homepage]
user image
Antwort von perlubgs@perl.de

Quote
Spaces in the glob denote multiple patterns. You must escape spaces that
are intended as literal spaces in the pattern. From the documentation
for File::DosGlob

 Spaces in the argument delimit distinct patterns, so "glob('*.exe
 *.dll')" globs all filenames that end in ".exe" or ".dll". If you want
 to put in literal spaces in the glob pattern, you can escape them with
 either double quotes, or backslashes. e.g. "glob('c:/"Program
 Files"/*/*.dll')", or "glob('c:/Program\ Files/*/*.dll')". The argument
 is tokenized using "Text::ParseWords::parse_line()", so see
 Text::ParseWords for details of the quoting rules used.

Regards,
Randy.


Oder kurz: RTFM...

Jetzt muss ich nurnoch heraus bekommen, wie ich automatisiert meine File::Spec-catfile() - erzeugten Pfade entsprechend gequotet bekomme.\n\n

<!--EDIT|pktm|1123945370-->
http://www.intergastro-service.de (mein erstes CMS :) )
Rambo
 2005-08-14 12:30
#57171 #57171
User since
2003-08-14
803 Artikel
BenutzerIn

user image
guter hinweis
mal sehen ob das evtl. auch bei Ncopy funktioniert.

gruss rambo
pktm
 2005-08-14 13:30
#57172 #57172
User since
2003-08-07
2921 Artikel
BenutzerIn
[Homepage]
user image
[quote=Rambo,14.08.2005, 10:30]guter hinweis
mal sehen ob das evtl. auch bei Ncopy funktioniert.

gruss rambo[/quote]
Meinst du den von renee, mit opendir, readdir und closedir? :-D
http://www.intergastro-service.de (mein erstes CMS :) )
Rambo
 2005-08-14 20:45
#57173 #57173
User since
2003-08-14
803 Artikel
BenutzerIn

user image
nein wir hatten mal einen beitrag mit file::Ncopy bei dem
ich die probleme hatte das es mit verzeichnissen mit leerzeichen auch nicht ging.
pktm
 2005-08-14 23:53
#57174 #57174
User since
2003-08-07
2921 Artikel
BenutzerIn
[Homepage]
user image
Naja, ich habe da das Problem dass ich meine Dateipfade immer von File::Spec erzeugen lasse um die Scripten auch mal eben auf Linux laufen lassen zu können.
Aber wenn ich dann erst noch alles per RegEx nachbearbeiten muss finde ich das echt ätzend...
http://www.intergastro-service.de (mein erstes CMS :) )
ptk
 2005-08-15 20:56
#57175 #57175
User since
2003-11-28
3645 Artikel
ModeratorIn
[default_avatar]
Man koennte ja ein glob() schreiben, dass Leerzeichen nicht als Spezialzeichen für das Globbing auffasst. Dann waeren viele Probleme behoben!

(Such)

Ah, das gibt es schon. Aus der File::Glob-manpage:
Code: (dl )
Due to historical reasons, CORE::glob() will also split its argument on whitespace, treating it as multiple patterns, whereas bsd_glob() considers them as one pattern.
<< |< 1 2 >| >> 11 Einträge, 2 Seiten



View all threads created 2005-08-13 03:13.