Re: More died on open command (from 55103)

From: John W. Krahn (krahnj_at_acm.org)
Date: 11/11/03


To: beginners@perl.org
Date: Mon, 10 Nov 2003 15:24:07 -0800

Ganesh Shankar wrote:
>
> Hello all,

Hello,

> I tried modifying the open command ar suggested and got the enclosed
> errors. Also, I'm working with Activestate Activeperl 5.6 on a Windows
> 2000. Also, from the syntax of the readdir example, the test is to the
> left of the readdir command. Does this mean I should place my file
> processing block to the left of the readdir command. That would be one
> ugly statement.
>
> [snip]
>
> use warnings;
> use strict;
>
> my @files = ();
> my $folder = 'input';
> # Open the input folder
> unless (opendir(FOLDER, $folder)) {
> print "Cannot open folder $folder!\n\n";
> exit;
> }
>
> #read the contents of the folder (files and subfolders)
>
> chdir($folder); #added this line after failing with open commands below.
>
> print "Switching to folder $folder!\n\n"; # It's going to the correct
> folder
>
> @files = readdir(FOLDER);
>
> #Close the folder
>
> print "\n\n Here are the files in the folder\n";
> #print out the filenames, one per line
> print join( "\n", @files), "\n";# Prints out correct filenames
>
> closedir(FOLDER);
>
> foreach my $seqfilename (@files){
>
> $seqfilename = '';
> open (TXTFILE,"<$seqfilename") or die $!; #dies on this line.Replace with

This won't work because it is trying to open $seqfilename in the current
directory.

> open (TXTFILE,"<$folder/$seqfilename") or die $!; #Invalid argument at this line. Replace with

Windows apparently sends an EINVAL ("Invalid argument") when there are
certain non-printable characters in the file name! (Who knew?)

http://mail.python.org/pipermail/python-list/2002-March/090323.html

> open (TXTFILE,"<$folder\$seqfilename") or die $!; #No such file or directory error at this line

This won't work because the backslash will escape the dollar sign. If
you want the backslash character in a double quoted string you will have
to escape it (precede it with a backslash.)

John

-- 
use Perl;
program
fulfillment


Relevant Pages

  • Re: Saving a file to a users desktop.
    ... Take a look at the ADDBS() function. ... backslash at the end you'll get something like ... windows folder. ... What if windows is installed on the D drive? ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Open Windows Explorer to a specific folder
    ... would like Windows Explorer to open to a folder of my choosing. ... backslash in registry keys must be prefixed by another backslash, ...
    (microsoft.public.windowsxp.customize)
  • Re: recover compacted folders
    ... Because of this tendency of attachments to infect, ... , then wasted space is generated in that file, and the folder must be ... Windows 2000 and Windows XP. ... Windows XP Service Pack 2 Resources for IT Professionals ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: OE & SP2 missing Local Folders
    ... , then wasted space is generated in that file, and the folder must be ... Turn off email scanning in your antivirus software. ... Windows 2000 and Windows XP. ... Windows XP Service Pack 2 Resources for IT Professionals ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: Lost Emails Information During "Compacting" of Folders
    ... , then wasted space is generated in that file, and the folder must be ... Options | Maintenance for each Identity you have, and then compact manually ... Turn off email scanning in your antivirus software. ... Windows 2000 and Windows XP. ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)