Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Accessing a folder whose name changes daily

by Jim (Curate)
on Dec 18, 2012 at 17:50 UTC ( #1009438=note: print w/ replies, xml ) Need Help??


in reply to Accessing a folder whose name changes daily

I agree with salva here. Simple globbing fits the bill nicely.

If you're a Windows programmer, not a Unix/Linux programmer, then you may not already be familiar with the ability to use globs (wildcards) for folder names as well as for file names. As a Perl programmer, folder globbing is a powerful tool you'll want to add to your toolkit.

Here's a concrete example using File::Glob::bsd_glob:

C:\>perl -MFile::Glob=bsd_glob -E "say bsd_glob('C:/Program Files/Micr +osoft Office/*/WINWORD.exe')" C:/Program Files/Microsoft Office/Office12/WINWORD.exe C:\>

(There could be a file named WINWORD.exe in more than one subfolder of C:\Program Files\Microsoft Office, so the value returned by bsd_glob is a list, not a scalar.)

Many of my Perl scripts running on Windows use File::Glob like this:

use English qw( -no_match_vars ); use File::Glob qw( bsd_glob ); @ARGV = map { bsd_glob($ARG) } @ARGV;

Jim


Comment on Re: Accessing a folder whose name changes daily
Select or Download Code
Re^2: Accessing a folder whose name changes daily
by JennieInMI (Acolyte) on Dec 18, 2012 at 18:34 UTC

    I do want to learn how to do this! I am on Windows too. I had tried simply using a metacharacter in the file path before I came and asked, but Perl kept telling me it couldn't use ctime on an undefined value. For some reason, no interpolation was taking place and the asterisk itself was being read as part of the path. I'm still not sure why. Thank you for posting this, especially with the examples. Examples are really helpful for someone less experienced. I will study this. Thank you again.

      I do want to learn how to do this!

      And we monks want to help you learn!

      I am on Windows too.

      I guessed that. (You mentioned "command prompt," which is Windows lingo.)

      I had tried simply using a metacharacter in the file path before I came and asked, but Perl kept telling me it couldn't use ctime on an undefined value. For some reason, no interpolation was taking place and the asterisk itself was being read as part of the path. I'm still not sure why.

      Nor can we be sure why based solely on your description of what's happening. We need more information. Show us what you tried that didn't work.

      Thank you for posting this, especially with the examples. Examples are really helpful for someone less experienced.

      Then you understand how showing us examples of your problem and the solution you tried that didn't work will help us help you.

      Jim

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1009438]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2014-09-03 07:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls