[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

getting list of files and error checking

Posted on 2009-04-01
3
Medium Priority
?
154 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 400 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 1600 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
Six Sigma Control Plans

649 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