Solved

getting list of files and error checking

Posted on 2009-04-01
3
148 Views
Last Modified: 2012-05-06
my @directoryListing = <*.txt *.TXT *.doc *.DOC *.pdf *.PDF>;

Is this a good way of retrieving the list of files in the current working directory?
how would you add error checking to this?
0
Comment
Question by:NewtonianB
3 Comments
 
LVL 40

Assisted Solution

by:mrjoltcola
mrjoltcola earned 100 total points
Comment Utility
Depends on which errors you want to check.

Given 1 line of code, the only things I can think of, given your code, is to verify that you are in a valid working directory prior to issuing the directory listing, you do that by checking the return value of chdir().

Maybe you had something else in mind, can you clarify?
0
 

Author Comment

by:NewtonianB
Comment Utility
are there predefined lists I can feed to this file retrieval system?
let's say I wanted to encompass all the possible types of document files or image files, is there a way to do that or do I have to manually enter each extension both lowercase and uppercase?

in terms of error I was wondering wether directory listing would ever be denied to the scirpt
0
 
LVL 39

Accepted Solution

by:
Adam314 earned 400 total points
Comment Utility
Specifying the extensions the way you have would miss mixed case extensions, such as *.Pdf (if the file system is case sensitive).  Here is a way to not have to deal with that.

You will still need to specify the extensions you want to include.  Just include all of the extensions following the same pattern - I've included .txt, .doc, and .pdf files so far.
my @directoryListing = grep {/\.(txt|doc|pdf)$/i} <*>;

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now