[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

Reading a filename

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
eg.sdat328.zip, sdat542.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.

S

0
Simon336697
Asked:
Simon336697
1 Solution
 
TintinCommented:
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";
     }

  }
}
0
 
Simon336697Author Commented:
Thanks Tintin champion.

S
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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now