Loading ...
Sorry, an error occurred while loading the content.
 

Re: convert the files in a directory

Expand Messages
  • Damien Carbery
    ... Can t open ... Note the mix of forward and back slashes. I recommend using forward slashes, even on Windows. So, try changing this to:
    Message 1 of 2 , Jul 31, 2007
      --- In perl-beginner@yahoogroups.com, "elavazhagan perl"
      <elavazhagan.perl@...> wrote:
      >
      > Hai,
      >
      > While executing the following scripts , the diagnostic mag got as
      Can't open
      > the dir No such file or directory.orelse can I use "." instead of "$dir"
      > there.
      > Advance thanks for ur help.
      >
      > #!/usr/bin/perl
      > use strict;
      > use warnings;
      > my($dir,$i,$files,@files);
      > undef $/;
      > $dir="D:\ELAVAZHAGAN/JULY/DOIT";
      > opendir(FDIR,"$dir") or die ("Can't open the dir $!\n");
      > @files=grep(/\.pl?$/,readdir(FDIR));
      > for ($i=1;$i<=@files;$i++)
      > {
      > print"Processing file: $files[$i]\n";
      > open(FIN,$files[$i]) or die ("Can't open file $!");
      > $files=<FIN>;
      > close FIN;
      > $files[$i] =~ s/\.pl?$/\.xml/is;
      > open(FOUT,">$files[$i]") or die ("can't open files$!\n");
      > print FOUT $files;
      > close FOUT;
      > }
      >

      > $dir="D:\ELAVAZHAGAN/JULY/DOIT";
      Note the mix of forward and back slashes.
      I recommend using forward slashes, even on Windows.
      So, try changing this to:
      $dir='D:/ELAVAZHAGAN/JULY/DOIT';
      or only use backslashes, in pairs:
      $dir="D:\\ELAVAZHAGAN\\JULY\\DOIT'
      I use single quotes because there are no variables in the string.
    Your message has been successfully submitted and would be delivered to recipients shortly.