Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
it isn't short but this is it:
use Cwd; $homedir = getcwd(); @dir = $homedir; $feddir = ""; @allfiles = (); @dirnw = (); @directory = (); @files = (); sub putdir { $directories = ""; $spacefiles = ""; opendir (THISDIR, "$feddir") or die "dying! $feddir: $!"; @allfiles = readdir THISDIR; closedir THISDIR; foreach $a (@allfiles) { chomp $a; if ( $a eq "." || $a eq ".." ) { next; } elsif ( -d $a ) { if ($directories eq "") { $directories = "$a"; } else { $directories = "$directories+" . "$a"; } } else { #it should detect if the file has a space in i +t first $rest = ""; (undef,$rest)=split(/\s+/,$a,2); if ($rest ne "") { if ($spacefiles eq "") { $spacefiles = "$feddir/$a"; } else { $spacefiles = "$spacefiles+" . + "$feddir/$a"; } } } } $rtrn = "$directories%" . "$spacefiles"; return $rtrn; } do { foreach $feddir (@dir) { chomp $feddir; $output = putdir(); ($dirs,$file) = split(/\%/,$output); (@files) = split(/\+/,$file); open (DATABASE, ">>/$homedir/listofiles"); foreach $f (@files) { chomp $f; print (DATABASE "$f\n"); #$g = $f; #$g =~ s/\s+/_/g; #rename $f, $g or die "can't rename! $ +f, $g: $!"; #$g = ""; } close DATABASE; (@directory) = split(/\+/,$dirs); foreach $d (@directory) { chomp $d; (undef,$restodir)=split(/\s+/,$d); if ($restodir ne "") { open (DATABASE2, ">>/$homedir/listodir +s"); print (DATABASE2 "$d\n"); close DATABASE2; #$h = $d; #$h =~ s/\s+/_/g; #rename $d, $h or die "can't rename! $ +d, $h: $!"; #$h = ""; } } push @dirnw, @directory; @directory = (); } @dir = (); @dir = @dirnw; @dirnw = (); } until (@dir == "")

In reply to Re: Re: opendir and directories that have spaces in them by Anonymous Monk
in thread opendir and directories that have spaces in them by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2024-04-19 08:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found