LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-24-2011, 01:09 PM   #1
bloodyscript
Member
 
Registered: Apr 2006
Distribution: Sabayon linux 5.1
Posts: 182

Rep: Reputation: 15
python os.walk file search question [SOLVED]


hi i was wondering if its possible to have pygtk .get_text() specify a filename for os.walk() to find while its traversing the directory tree?

Last edited by bloodyscript; 09-24-2011 at 05:07 PM.
 
Old 09-24-2011, 02:14 PM   #2
bloodyscript
Member
 
Registered: Apr 2006
Distribution: Sabayon linux 5.1
Posts: 182

Original Poster
Rep: Reputation: 15
currently my os.walk code list's all the files in all directories under the specified directory.

top = /home/bludiescript/tv-shows
for dirpath, dirnames, filenames in os.walk(top):
for filename in filenames:
print os.path.join([dirname, filename])
so how could i add

glob.glob(search)
search = self.search.get_text

to search for the pattern that i type in the gtk.Entry
 
Old 09-24-2011, 02:52 PM   #3
bloodyscript
Member
 
Registered: Apr 2006
Distribution: Sabayon linux 5.1
Posts: 182

Original Poster
Rep: Reputation: 15
i believe i solved it

search = self.search.get_text()
top = /home/bludiescript/tv-shows
for dirpath, dirnames, filenames in os.walk(top):
for filename in filenames:
if fnmatch.fnmatch(filename, search)
print os.path.join([dirname, filename])

but now how could i print os.path.join([dirname, filename]) to a list if self.list = []
and self.contents = "/n".join(self.list)

in fact its not sovled does fnmatch look for the whole filename or can it be a single word in a file/files

on python docs it shows useing the [seq] to match and character in seq so i tried fnmatch.fnmatch(filename, [search]) and it gave an error unhashable list.

Last edited by bloodyscript; 09-24-2011 at 03:39 PM.
 
Old 09-24-2011, 05:09 PM   #4
bloodyscript
Member
 
Registered: Apr 2006
Distribution: Sabayon linux 5.1
Posts: 182

Original Poster
Rep: Reputation: 15
search = self.search.get_text()
top = /home/bludiescript/tv-shows
for dirpath, dirnames, filenames in os.walk(top):
for filename in filenames:
if re.findall(filename, search)
print os.path.join([dirname, filename])

i changed the fnmatch function to re.findall and it fixed my initial problem
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Python: search for string in a list or file chess Programming 3 08-22-2007 04:22 PM
python gui file dialog question mulciber Programming 0 07-26-2005 07:37 AM
Python Question - moving file across filesystems drj000 Programming 3 01-26-2005 11:36 AM
python call function in same file(very newbie question) rmanocha Programming 2 11-21-2004 12:04 AM
Quick VIM question (unhighlighting search terms after search) lrt2003 Linux - Newbie 5 05-08-2004 05:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration