use File::Find; use Cwd; my $homedir = getcwd(); open DATABASE, ">>$homedir/listofiles" or die "can't open listofiles: $!\n"; open DATABASE2, ">>$homedir/listodirs" or die "can't open listodirs: $!\n"; File::Find::find( sub { return if /^\.\.?$/; return unless /\s/; if ( -d $_ ) { print DATABASE2 "$File::Find::name\n"; } else { print DATABASE "$File::Find::name\n"; } ( my $newName = $File::Find::name ) =~ s/\s+/_/g; print STDERR "renaming $File::Find::name to $newName\n"; # rename($File::Find::name, $newName) or die "can't rename : $!\n"; }, $homedir ); close DATABASE; close DATABASE2;