Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid argument in opendir()

Status
Not open for further replies.

gorgor

Programmer
Aug 15, 2002
164
US
I've noticed that Perl's opendir() command does NOT like the '-' (dash) symbol. Is there a way around this? I'm writing a console Perl script that takes an @ARGV for the name of a directory and I need to be able to include special characters in the directory name such as a dash.
 
Can you provide an example? and a code snibbit. I've never come across this problem, nor can i reproduce it.

jaa
 
I reproduced the error by using this snippet:

my $dir = 'q:/2002-03-26';

#Open the directory to read its contents
opendir(DIR,$dir) || die $!; #this is line 82

the error:
"Invalid argument at script.pl line 82."


I've tried escaping the dashes, using double quotes around $dir, single quotes around $dir, double quotes around the $dir assignment, just about everything I can think of. Maybe I'm just crazy?
 
I've tried to reproduce your problem by using following code:
$dir="C:\\temp\\2002-08-09";
opendir(DIR, $dir)||die $!;
@dateien=readdir DIR;
closedir DIR;
print "$dir\n";
print "@dateien";
Starting the skript I did not get any errors.
I had following output:
C:\Perlskript>perltest1.pl #Skriptaufruf
C:\temp\2002-08-09
. .. logfile.log ordner1 ordner2 ordner3
maybe I didn'd quite understand what you were asking for.
 
that's it. It's not letting me open a directory that has a dash in its name. I tried to replace the name of the directory to a directory that doesn't have dashes in its name and it opened it fine. hmmmm
 
I couldn't reproduce this on XP or linux. Have you tried escaping the dashes in a double quoted string?
Code:
my $dir = "2002\-03\-26";
This still works for me. It doesn't work if they are escaped using s/// so that wouldn't help if you are reading the dirs in from STDIN or a file.

jaa
 
That was REALLY dumb! I had permissions set to administrators only. Works fine now! That directory was the only directory out of about 8 that had the wrong permissions set, so I didn't even think to check it. Well, thanks for the help!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top