|Just another Perl shrine|
Re: Unable to read files from a directoryby graff (Chancellor)
|on May 14, 2009 at 03:43 UTC||Need Help??|
First, add use strict;
Next, change the "readdir" line to be like this:
That will assure that the @files array contains only things that can properly be opened as files (i.e. things that are not other directories).
Then, as mentioned above, make sure your "die" messages include the actual variable that contains the thing you were trying to open (directory name at line 2, file name at line 7). When you get a "permission denied" error on trying to open a file, check whether some other windows app happens to have that file open. (I gather that on Windows, when some process has a file opened for read/write access, other processes are not allowed to access that file.)
Once you know the specific name of the file that cannot be opened, you could check by other means to see whether some other program might have the same problem with that particular file.
Just a thought: since you are (presumably) looping over a number of files and just reporting some sort of result for each one, why not handle the open failures like this:
Finally, I'm puzzled by the apparent logic of the inner-most for loop. Looks like it shouldn't really be a loop, but in any case, it doesn't make sense.
I don't understand what you meant in your later reply when you said "I opened all the permissions". What does that mean, exactly?