glob.glob() function in python scripting

A forum for general discussion of the Python programming language.

glob.glob() function in python scripting

Postby sivakumar » Thu Apr 10, 2014 7:12 am

Hi
I need some suggestion on glob function.

I am trying to write a python program to grep some specific files in a particular directory.
In the directory i have some files like below
abc.log
abc.pid
abc.tar
gadd.tar
gat.log
gat.tar
in this directory i need to grep onlu my hostname files, my host name is abc, so the output should be
abc.log
abc.pid
abc.tar

I have written the program as below

Code: Select all
#!/usr/bin/python
import os, re, tty, sys, termios, glob, subprocess, time, socket
userhome = os.getenv( 'HOME')
host = socket.gethostname()
os.chdir(userhome+'/.orbit')
host_files = glob.glob(-------) ##here I got struck.


Please help me how to fill glob.glob line in the above coding
Last edited by stranac on Thu Apr 10, 2014 9:12 am, edited 1 time in total.
Reason: First post lock.
sivakumar
 
Posts: 1
Joined: Thu Apr 10, 2014 7:01 am

Re: glob.glob() function in python scripting

Postby metulburr » Thu Apr 10, 2014 9:16 am

Code: Select all
glob.glob('abc*')
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1471
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: glob.glob() function in python scripting

Postby stranac » Thu Apr 10, 2014 9:20 am

To match the files starting with "abc.", use the pattern "abc.*"
The special characters you can use are listed in the fnmatch docs.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 3 guests