Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#! perl -w # Copy files to another directory use strict; use File::Copy; use File::Spec::Functions qw(catfile); my $line = 'C:\sql server scripts\test'; opendir MYDIR, $line or die "Could not opendir $line: $!\n"; my @allfiles = grep { $_ ne '.' and $_ ne '..' } readdir MYDIR ; closedir(MYDIR); my @files = grep { !-d } @allfiles ; my @dirs = grep { -d } @allfiles ; print @files." files and ".@dirs." directories in $line\n" ; print map "$_\n", @allfiles; my @select_files = grep /\.cfm\z/i, @files; for my $file (@select_files) { copy catfile($line,$file), catfile("C:\\temp", $file); } my $newdir = 'C:\\temp'; opendir MYDIR, $newdir or die "Could not opendir $newdir: $!\n"; my @all_files = grep { $_ ne '.' and $_ ne '..' } readdir MYDIR ; closedir(MYDIR); my @change_files = grep { !-d } @all_files; foreach my $get_files (@change_files) { my $newfile = $get_files; $newfile =~ s/\.cfm$/.html/; if (-e $newfile) { warn "can't rename $get_files to $newfile: $newfile exists\n"; } elsif (rename $get_files, $newfile) { print "file was renamed to $newfile\n" } else { warn "rename $get_files to $newfile failed: $!\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Renaming Files
by dws (Chancellor) on Feb 19, 2003 at 19:39 UTC | |
|
Re: Renaming Files
by Shendal (Hermit) on Feb 19, 2003 at 19:49 UTC | |
|
Re: Renaming Files
by Tomte (Priest) on Feb 19, 2003 at 19:54 UTC | |
by thor (Priest) on Feb 20, 2003 at 00:08 UTC | |
by Tomte (Priest) on Feb 20, 2003 at 06:21 UTC | |
by thor (Priest) on Feb 20, 2003 at 12:36 UTC |