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. VAR.set(nr) # Set number of files as a variable for label Snippet import os for (root, dirs, file) in os. You can iterate the files list and access the files in the directory. It’ll return two separate lists of files and folders. Nr = LIST.size() # Get current number of files in listbox To display only the files in a directory, you can use the os.walk () method. If youre on Python 3.5+, you can use pathlibs glob() instead of the glob module alone. 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 '/' UsePATH = '/nfzcae/nvh_mdp/Messdatenbank_Powertrain'įileLevels = # code of interest is belowįor f in glob.iglob(os.path.join(path, d,'*COMPARE.mat')): Your code lacks a if name 'main': starting section. If you're going to write python, PEP8 states snakecase should be used as the expected style. The code which I wrote is as follows: lete(0,END) # this is a list view Firstly some tips: Your code uses a mixture of snakecase and camelCase, you should stick to a specific style. I was thinking of multiprocessing or threading. The function which I wrote works, but I want to make it more efficient and faster. 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. I have a directory with lot of files and folders in it. For matching the file name name in python you can use fnmatch module.I will provide you a sample code from the documentation.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |