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 2092 miller 1,089
Recognized Expert Top Contributor
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.
numberwhun 3,509
Recognized Expert Moderator Specialist
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
miller 1,089
Recognized Expert Top Contributor
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 protect you from nasty viruses.
http://promotions.yahoo.com/new_mail
|
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. I can do this with the glob() function,
but I can't seem to put in a directory other than one within the
webroot. For example, I can only put...
|
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 method is to
be inherited by all listing classes to allow for
* list-wide deletion of latent server-created ZIP files for security
purposes
*
|
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 file date modied and check
the date. I know how to look at each file name and I know how to remove
the file. I just can't figure out how to get access...
| |
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() + '/images/')
self.folder_new=PhotoImage(file=self.imagedir + 'folder_new.gif')
self.save=PhotoImage(file = self.imagedir + 'save.gif')...
|
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 the
contents in those files into a new one (it's XML and I have to
concatenate some subelements, about 4 levels below the root
element). It all...
|
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 ,
H20080102.txt,H20080103.txt,H20080104.txt,H20080105.txt etc......
i already got a python script to read and insert a single text files
|
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 efficient manner?
here it is...
from string import split
from os.path import isdir,join,normpath
from os import listdir
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |