Reading a filename

Posted on 2007-07-19
Last Modified: 2010-04-16
Hi guys!

Hope you can help.

I want to, through perl, do the following....

Find a particular file.
The file is:         sdat*.zip

The path is: c:\sdat*.zip
where sdat could be sdat<any number or numbers>.zip,, any number at all.

I want to be able to:
a) Determine if sdat*.zip exists (if -e)
b) Read the filename (not read its contents), but the name of the file into a variable, minus the dot and file extension, and minus the sdat part, so only the number is to go into a variable.
c) Compare this number against another eg.5000
d) blah blah.

Basically, its just the first 2 parts i need help with.

Any help greatly appreciated.


Question by:Simon336697
    LVL 48

    Accepted Solution

    foreach (<C:/sdat*.zip>) {
      if (/sdat(\d+)\.zip/) {
         my $num  = $1;

         if ($num == 5000) {
            print "$num equals 5000\n";
         else {
            print "$num does not equal 5000\n";

    LVL 1

    Author Comment

    Thanks Tintin champion.


    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
    I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
    Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    745 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

    15 Experts available now in Live!

    Get 1:1 Help Now