in reply to Checking for existing filename before renaming file

Hi. Seems the above replies have already solved your problem. But just a point of (hopefully) correction here. Do you have to keep explicitly using $_ ? Your code would be much more readable, you know, if you didn't do that. And use \s for your space, instead of a space character.
use strict; my $file = '.'; opendir(MYDIR,$file); my @files = readdir(MYDIR); foreach (@files) { next if( m/^\.+$/); if ( m/\s/g ) { my $oldfile = $_; s/\s/_/g; if (! -e) { rename $oldfile, $_; } else { print "Could not rename $oldfile because ${_} +name already exists and can not be overwritten\n"; } } print "$_\n"; }

Replies are listed 'Best First'.
Re: Re: Checking for existing filename before renaming file
by Anonymous Monk on Feb 14, 2003 at 18:18 UTC
    Thanks