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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.