in reply to -f not identifying .txt files
This makes no sense, show some code please.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: -f not identifying .txt files
by rucha (Initiate) on Sep 24, 2010 at 09:56 UTC | |
@dHarry, @tirwhan: Sorry for my mistake. I joined the forum today and was expecting that there will be an option to upload my code file directly. I couldn't find it. Discovered the tags later. Anyway, here's my code. (I have given the whole code so that exact mistake can be pointed out)
When I use (!-d $_) to identify files, .txt, .pdf files are printed, but their last modified (no. if days) is not printed. | [reply] [d/l] |
by tirwhan (Abbot) on Sep 24, 2010 at 10:48 UTC | |
Check the working directory in which you are executing the script. I'd wager you have the .pl and Dumper.pm files in there, but not the others. To fix your script change, on line 20 of the code given if(-f $_)to if(-f "$p/$_") All dogma is stupid. | [reply] [d/l] [select] |
by rucha (Initiate) on Sep 28, 2010 at 04:41 UTC | |
I prepended the directory path to the filename, and now it's printing all the files along with last modified no. of days ago correctly. | [reply] |
by dHarry (Abbot) on Sep 24, 2010 at 11:36 UTC | |
I think the solution has already been suggested, I would just like to point you to the documentation (readdir): If you're planning to filetest the return values out of a readdir, you'd better prepend the directory in question. Otherwise, because we didn't chdir there, it would have been testing the wrong file. Harry | [reply] [d/l] |
by roboticus (Chancellor) on Sep 24, 2010 at 10:41 UTC | |
If I had to guess, I'd guess that you have the .pl and .pm files in your current directory, and that d:/perlnew/ex/comp is a test directory, which contains the .pl and .pm files, along with other files. Since there's no directory prefix, the -f function is checking your local directory rather than the directory you've done the readdir from. If your current directory is actually d:/perlnew/ex/comp when you run your script, then I can't think of a reason that readdir would see the files and -f wouldn't. ...roboticus | [reply] |
by rucha (Initiate) on Sep 24, 2010 at 10:51 UTC | |
Hi, the file I'm running is in D:/perlnew/ex | [reply] |
by roboticus (Chancellor) on Sep 24, 2010 at 11:04 UTC | |