Solved

getting list of files and error checking

Posted on 2009-04-01
3
151 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 40

Assisted Solution

by:mrjoltcola
mrjoltcola earned 100 total points
ID: 24042468
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
ID: 24042589
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
ID: 24042669
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…

726 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