Solved

getting list of files and error checking

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 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