Unix filename wildcards in Python?
NickName:Ricky Robinson Ask DateTime:2013-04-11T21:10:59

Unix filename wildcards in Python?

How do Unix filename wildcards work from Python?

A given directory contains only subdirectories, in each of which there is (among others) one file whose name ends with a known string, say _ext. The first part of the filename always varies, so I need to get to the file by using this pattern.

I wanted to do this:

directory = "."
listofSubDirs = [x[0] for x in os.walk(directory)]
listofSubDirs = listofSubDirs[1:] #removing "."

for subDirectory in listofSubDirs:
    fileNameToPickle = subDirectory + "/*_ext" #only one such file exists
    fileToPickle = pickle.load(open(fileNameToPickle, "rb"))
    ... do stuff ...

But no pattern matching happens. How does it work under Python?

Copyright Notice:Content Author:「Ricky Robinson」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/15949694/unix-filename-wildcards-in-python

More about “Unix filename wildcards in Python?” related questions

Unix filename wildcards in Python?

How do Unix filename wildcards work from Python? A given directory contains only subdirectories, in each of which there is (among others) one file whose name ends with a known string, say _ext. The

Show Detail

how to specify wildcards in a filename for amazon EMR job

If I run a EMR job and specify wildcards in the directory path it all works fine e.g: s3n://mybucket///*/fileName.gz --- picks all files with name fileName.gz under subdirectories of mybucket How...

Show Detail

Prevent expansion of wildcards in non-quoted python script argument when running in UNIX environment

I have a python script that I'd like to supply with an argument (usually) containing wildcards, referring to a series of files that I'd like to do stuff with. Example here: #!/usr/bin/env python ...

Show Detail

List of files (which might contain wildcards) as arguments of a Python script

In many python scripts I find my self doing the following: for maybe_glob in sys.argv[1:]: for filename in glob.iglob(maybe_glob): print(filename) I have to do this because the script...

Show Detail

How to use filename wildcards with QCommandLineParser

Is there a problem with QCommandLineParser and filename wildcards in Windows? I'm using Qt 5.8.0 opensource on Windows to build a console application. I'm trying to build a command line utility t...

Show Detail

Using wildcards in file names using Python's SCPClient library

I want to copy files from remote machine using Python script to my local machine. I only know the extension of the file names so I want to use wildcards to express the file name. In addition, I w...

Show Detail

Python FTP from UNIX to Windows

I am running a python script on a UNIX server. My aim is to take the file from UNIX server and put it in Windows machine . #!/usr/bin/python import ftplib filename = "filename" ftp = ftplib.FTP("x...

Show Detail

How to run unix / shell commands with wildcards using Java?

I want to run some unix/shell commands in Java and process the output. I used getRuntime.exec(), but it is not giving correct output for some commands like ls directory_path/*.tar.gz . For that com...

Show Detail

Use of wildcards in a fileref generating Insufficient Authorization message

Is there a SAS system option, configuration parameter, or other scenario that might disable the use of wildcards in a fileref? The following code works: FILENAME THEFILE "/sasrep/POC/UNGMPW.PRO" ;...

Show Detail

Running unix checksum command in Python

Is there anyway we can run below unix command in Python. csum -h SHA1 <filename> The checksum produced in python would be stored and supposed to match with the checksum produced by unix com...

Show Detail