473,322 Members | 1,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

help needed using os.path.walk [solved]

hello friends,

i am using the os.path.walk to search to filter the files with the given word, this function i m using in many modules. i just want to place this function in some class and call it whenever required by passing the necessary word. for e.g i want to filter files with "Spec" which is specification documents and store in some list, and other time with word "doc" like this many times...so i want to place it in some class placed in some file and access it by calling the function with the filtering word required, like spec, doc etc.... can any one say me how to pass this filtering word to the calling function from os.path.walk...


here is some sample code which i use to filter the documents with spec:

def finddocfiles(option,dir,files):
for index in files:
#print index
if index.rfind("Spec")!=-1:

# all spec files are stored in list_Sharedfiles list
option.append(dir+os.sep+index)

this is called by os.path.walk(path,finddocfiles,list_files)


so i use this very frequently to filter files, so any one please suggest me how to pass the filtering word i.e here "Spec" or "doc" waiting for ur reply...thans in advance
Oct 16 '06 #1
1 5965
bartonc
6,596 Expert 4TB
walk( path, visit, arg)
Calls the function visit with arguments (arg, dirname, names)

arg can be anything including a tuple, right.
so use

Expand|Select|Wrap|Line Numbers
  1. def finddocfiles(options, dir, files): 
  2.     for index in files:
  3.         #print index
  4.         if index.rfind(options[1])!=-1:
  5.  
  6.         # all spec files are stored in list_Sharedfiles list
  7.         options[0].append(dir+os.sep+index)
  8.  
  9.  
  10. key = "Spec"
  11. os.path.walk(path, finddocfiles, (list_files, key))
  12.  
Oct 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: hokieghal99 | last post by:
This script is not recursive... in order to make it recursive, I have to call it several times (my kludge... hey, it works). I thought os.walk's sole purpose was to recursively walk a directory...
8
by: ianaré | last post by:
Hey all, if i use a os.walk() to append files to a list like so... files = root = self.path.GetValue() # wx.TextCtrl input filter = self.fileType.GetValue().lower() # wx.TextCtrl input...
5
by: EP | last post by:
This inquiry may either turn out to be about the suitability of the SHA-1 (160 bit digest) for file identification, the sha function in Python ... or about some error in my script. Any insight...
3
by: Kilicaslan Fatih | last post by:
When I push a button to trigger the code: def runCCCC(self, event): cmd_out = self.A_com() if App.runF != "": os.mkdir('C:\copiedFiles') for item in App.runF: App.beCopied = str(item)...
46
by: Bruce W. Darby | last post by:
This will be my very first VB.Net application and it's pretty simple. But I've got a snag in my syntax somewhere. Was hoping that someone could point me in the right direction. The history: My...
5
by: Saabster | last post by:
Hi all, I'm fairly new to VB.NET but have more experience with VB6 and earlier. I'm trying to create an application that will move files from one folder to another. Here is the scenario. I...
11
by: cybervigilante | last post by:
I can't seem to change the include path on my local winmachine no matter what I do. It comes up as includ_path .;C:\php5\pear in phpinfo() but there is no such file. I installed the WAMP package...
8
by: inFocus | last post by:
Hello, I am new to python and wanted to write something for myself where after inputing two words it would search entire drive and when finding both names in files name would either copy or move...
0
by: Paul Lemelle | last post by:
Jeff, Thanks for your reply. I would like to like the absolute path of a directory. I thought that os.listdir just returns the nam itself in a data list. I noticed that none was being return...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.