in reply to visit directories and more...

Sorry, wrong script .. I mean this script:
#!/usr/bin/perl -w sub dir_explorer { my $dir = $_[0]; opendir(DIR,$dir) or die "Konnte Verzeichnis $dir nicht öffnen: $!"; my @verzeichnis = readdir(DIR); close (DIR); foreach $entry (@verzeichnis) { if(-f $entry) { # formatieren($entry); print ("$entry ist ein file ! \n"); } else { next if $entry =~ /^.\.?$/; # . und .. überspringen print ("$entry ist ein directory ! \n"); dir_explorer($entry); } }; }; dir_explorer("/home/dub/Stelle");

Replies are listed 'Best First'.
Re: Re: visit directories and more...
by WhiteBird (Hermit) on May 25, 2003 at 14:29 UTC
    Your first request indicated that you wanted to add the information to a text file, and the code you posted originally had the steps to create and open a FILE. This version is missing that step. Are you still trying to write to a File with this version?

    Also, I wonder if you wouldn't want to skip the . and .. entries at the very beginning, and move
    next if $entry =~ /^.\.?$/;   # . und .. überspringen
    up to the beginning of your if block?
    WB

Re: Re: visit directories and more...
by star7 (Novice) on May 26, 2003 at 09:36 UTC
    @little,WhiteBird and others Thank you. I read the tutorial about FILE::Find and wrote a new script. But there is a new problem. I hope you can help me:
    #!/usr/bin/perl -w use File::Find; find(\&print_name_if_dir, "/home/dub/Stelle"); sub print_name_if_dir { my $file = $_; if (-d $file) { $dir=$file; open(FILE, "> $dir") or die "Konnte $dir nicht mit Schreibrecht +en öffnen: $!\n"; close(FILE); }; if (-f $file) { open(FILE, ">> $dir") or die "Konnte $dir nicht öffnen: $!\n"; print FILE "$file\n"; close(FILE); }; };
    1.if-command: open(FILE,"> $dir") - I want create a new file (text-file) which has the name of the visited directory.
    But $dir contains the directory. How can i solve this problem ?