I have a script where I am using glob to get a list of folders that end in "*import", but I am trying to change my directory to the previous one.
Here is what I have:
@directories = glob("*import");
@directories = sort { $b <=> $a } @files;
I can't figure out how to make glob go back one directory. I am looking for something similiar to the Unix "cd .." command.
I have tried glob("../*import") and dozens of variations, but nothing works.
Thanks
4 2086
How I would do it: -
use File::Spec::Functions qw(updir);
-
-
use strict;
-
use warnings;
-
-
my @files = do {
-
local *PARENTDIR;
-
opendir(PARENTDIR, updir) or die "Can't open dir: $!";
-
grep {/import$/} readdir(PARENTDIR);
-
};
-
-
print "@files";
-
Alternatively, just use chdir.
- Miller
I am an idiot.
I was using this code (that I had used earlier):
@files = glob("*import");
@files = sort { $b <=> $a } @files;
when I decided to change the word "files" to directory - and so I did this:
@directory = glob("*import");
@directory = sort { $b <=> $a } @files;
As you can see, I did not change the third "@files" on the sort line. Once I changed it to "@directory", it worked.
I guess that I should quit programming at 2:00 a.m. - after that, I am not thinking clearly....
Thanks for your help.
Nah, I don't think you should quit the 2am suicide programming session(s), in fact I tend to get some really good work done during those weeeee morning hours. Instead, I would crank up the ol' tea pot and start steeping some tea (or whatever your beverage of choice is). Although the only issues I have truly had during those times are when I wake up with drool on the keyboard and an imprint of the keys on my cheek. Yeah, then you know you were up too long!
Glad you found your issue!
Regards,
Jeff
As you can see, I did not change the third "@files" on the sort line. Once I changed it to "@directory", it worked.
I don't know for sure, but I suspect that you are probably not including "use strict;" in your scripts. Or at least not this script. If you had, then once you changed the original my definition from "my @files" to "my @directory", all other instances of @files would no longer work and you would have been alerted to the error.
This is just a suspicion. But if it's true, then I strongly encourage you to change your script to include "use strict;" at the top. It would have saved you this headache, and will definitely save you future headaches.
- Miller
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sara Fwd |
last post by:
Can you guys also help me find a module that looks in
a directory and print out the names of the files in there?
__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps...
|
by: Gonnasi |
last post by:
With
>glob.glob("*")
or
>os.listdir(cwd)
I can get a combined file list with directory list, but I just wanna a
bare file list, no directory list. How to get it?
Tons of thanks in advance!
|
by: Jameson |
last post by:
Happy New Year, Everyone!
I am trying to figure out how to display a bunch of images (mainly
JPEGs, but possibly a few GIFs and PNGs as well) that are stored in a
local directory on the system....
|
by: comp.lang.php |
last post by:
Once again, I thought my class method deleteZip() would do the trick,
but it never deletes any .zip* file found in a directory:
/**
* Delete any latent ZIP files found in this album. This...
|
by: RAMohrmann |
last post by:
Greetings,
I am attempting to view all files in a directory and if those files
have not been modified within the last couple days I will remove them.
In order to do this I need to look at the...
|
by: Kevin Walzer |
last post by:
I am trying to create a number of Tk PhotoImages from a single
directory. Currently I am hard-coding file names and image names, like so:
def makeImages(self):
self.imagedir = (os.getcwd() +...
|
by: Wolfgang Draxinger |
last post by:
H folks,
I got, hmm not really a problem, more a question of elegance:
In a current project I have to read in some files in a given
directory in chronological order, so that I can concatenate...
|
by: jo3c |
last post by:
hi everybody
im a newbie in python, i have a question
how do u parse a bunch of text files in a directory?
directory: /dir
files: H20080101.txt ,...
|
by: royG |
last post by:
hi
i wrote a function to parse a given directory and make a sorted list
of files with .txt,.doc extensions .it works,but i want to know if it
is too bloated..can this be rewritten in more...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |