Solved

getting list of files and error checking

Posted on 2009-04-01
3
152 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

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 …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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

691 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