Reading a directory and Renaming the file
From: James Parsons (JamesP_at_407ETR.com)
Date: 10/30/03
- Next message: Aman Raheja: "Re: Reading files in a directory"
- Previous message: Dan Muey: "RE: Reading files in a directory"
- Next in thread: Dan Muey: "RE: Reading a directory and Renaming the file"
- Maybe reply: Dan Muey: "RE: Reading a directory and Renaming the file"
- Reply: Sudarshan Raghavan: "Re: Reading a directory and Renaming the file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: "'beginners@perl.org'" <beginners@perl.org> Date: Thu, 30 Oct 2003 14:29:25 -0500
Hi all
I've this Perl script to read all files in a directory and if it finds a
file with a certain then rename the file to header, but is doesn't search
the right directory and doesn't even look for the HPAY header.
Ops forgot to include the script.
#!/usr/bin/perl -w
use strict;
my $dir = "/interfaces/tdbank/test/";
opendir DIR, $dir;
my @files = readdir DIR;
my %hash = ('HPAY' => 'file1' ,
'HRET' => 'file2');
for (my $i=0; $i<scalar(@files); $i++) {
open FILE,"$files[$i]" || die "Unable to open file $files[$i] because
$!\n";
my $header = <FILE>;
print "header -->" , $header, "\n";
close FILE;
my $command = "mv $files[$i] $hash{$header}";
print "command -->", $command, "\n";
system $command;
}
And I get the following Errors:
Use of uninitialized value in concatenation (.) or string at ./process_f
iles.sh line 14.
command -->mv ..
Usage: mv [-i | -f] [--] src target
or: mv [-i | -f] [--] src1 ... srcN directory
readline() on closed filehandle FILE at ./process_files.sh line 11.
Use of uninitialized value in print at ./process_files.sh line 12.
header -->
Use of uninitialized value in hash element at ./process_files.sh line 14
.
Use of uninitialized value in concatenation (.) or string at
./process_files.sh line 14.
command -->mv file1
Usage: mv [-i | -f] [--] src target
or: mv [-i | -f] [--] src1 ... srcN directory
readline() on closed filehandle FILE at ./process_files.sh line 11.
Use of uninitialized value in print at ./process_files.sh line 12.
header -->
Use of uninitialized value in hash element at ./process_files.sh line 14
.
Use of uninitialized value in concatenation (.) or string at
./process_files.sh line 14.
command -->mv file2
Usage: mv [-i | -f] [--] src target
or: mv [-i | -f] [--] src1 ... srcN directory
etrprodftp /usr/local/sbin
Any help would be great..
James Parsons.
- Next message: Aman Raheja: "Re: Reading files in a directory"
- Previous message: Dan Muey: "RE: Reading files in a directory"
- Next in thread: Dan Muey: "RE: Reading a directory and Renaming the file"
- Maybe reply: Dan Muey: "RE: Reading a directory and Renaming the file"
- Reply: Sudarshan Raghavan: "Re: Reading a directory and Renaming the file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|