Reading a directory and Renaming the file

From: James Parsons (JamesP_at_407ETR.com)
Date: 10/30/03


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.



Relevant Pages

  • RE: Reading a directory and Renaming the file
    ... > even look for the HPAY header. ... There's probably a better way to move or rename the file but hey it works. ... > Use of uninitialized value in concatenation or string at ...
    (perl.beginners)
  • Re: Is it possible for me to have an alert pop-up when I open a do
    ... them and clean up the whole header. ... Dim TheWeekOfStr As String ... After I enabled macros and changed the security level, as per Dave Peterson, ... I got almost what I wanted, except that the pop-up box contains the font ...
    (microsoft.public.excel.misc)
  • Re: Zero terminated strings
    ... For doing major string handling you want a language where strings are a ... Check the header bytes as they are coming in and assume that you have dropped at least one byte if any of them are wrong. ... When you have a complete valid message (at the final destination, however many hops down the line it is) the final destination acknowledges it, and keeps sending ACKs for it until it receives the next message. ... The sender keeps trying to send it until it gets the acknowledgment. ...
    (comp.lang.c)
  • Re: Anyone interested in . . .
    ... there must *always* be an HPHP49-x header, ... which never means anything to other computers anyway. ... (this includes the ability to *receive* any file as a literal string, ...
    (comp.sys.hp48)
  • Re: Compile Error (ADO) Ron De Bruin
    ... Public Sub GetData(SourceFile As Variant, SourceSheet As String, _ ... Dim rsData As ADODB.Recordset 'THE ERROR IS ALWAYS HERE ... If Header = False Then ...
    (microsoft.public.excel.programming)