I know that threading does not work for nested for loops, so I am stuck in figuring out how to use the multithreading module for this problem. lete (0,END) this is a list view usePATH '/nfzcae/nvhmdp/MessdatenbankPowertrain' fileLevels code of interest is below for path, dirs, f in os.walk (usePATH): for d in dirs: for f in glob.iglob (os.path.join (path, d,'COMPARE.mat')): if 'COMPARE.mat' in f: if 'COMPARE.mat' in f and not 'MIN' in f and not 'MAX' in f / i. VAR.set(nr) # Set number of files as a variable for label All the filenames have the testing in the front and end with the date (08-05.txt). The pattern I need to match is something like:. Ideally, I would like to store it in an array once I get them. Nr = LIST.size() # Get current number of files in listbox I am trying to find all the files in the same directory as my script that has a filename matching a certain pattern. LIST.update_idletasks() # Update listbox after each element added LIST.insert(END,f) # Insert path with name string into the listbox If 'COMPARE.mat' in f: # if 'COMPARE.mat' in f and not 'MIN' in f and not 'MAX' in f / if 'COMPARE.mat' in f ) # if 'COMPARE.mat' in f and not 'MIN' in f and not 'MAX' in fįileLevels.append(f.split('/')) # Split path string at all '/' Navigating inside a directory tree: > p Path('/etc') > q p / 'init.d' / 'reboot' > q PosixPath ('/etc/init.d/reboot') > q.resolve() PosixPath ('/etc/rc.d/init.d/halt') Querying path properties: > q.exists() True > q.isdir() False Opening a file: > with q.open() as f: f.readline(). UsePATH = '/nfzcae/nvh_mdp/Messdatenbank_Powertrain'įileLevels = # code of interest is belowįor f in glob.iglob(os.path.join(path, d,'*COMPARE.mat')): The code which I wrote is as follows: lete(0,END) # this is a list view I was thinking of multiprocessing or threading. The function which I wrote works, but I want to make it more efficient and faster. 9 Answers Sorted by: 334 os.walk is the answer, this will find the first match: import os def find (name, path): for root, dirs, files in os.walk (path): if name in files: return os.path. I have a directory with lot of files and folders in it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |