python - Recursively listing a directory, but excluding any folders with a certain character -


I have two functions:

  1. I set up my own Dewey Digital Library in the format of decimal classification, so I've got 3-deep hierarchy of 10 + 100 + 1000 folders, as well as the directors are sometimes known deeply. This library structure includes my "books" which I have to list in a list (perhaps a searchable text document).

  2. The problem is that it would be better, although not absolutely necessary, if I can see the original directory name in a separate column next to each "book". There are "books" folders in my library that stand alone as items. When I prepared this system and made it, then I planned further so that every item in my library will have a tag in [] s in which the author's name is, for example, and Therefore, it is an idea that I will try to make a recursive list of all this, but when every repetition ends, [ in the name, directory or file]

How can I go about this? I know that Python knew little about Python (which was originally used to build library structure), and because it is on an external hard drive, I can do it either in windows or linux. My rude idea was to do some recursive lists, which checks the name of each directory or file for [, and if it does, stop and add it (with the parent's name) Directory) In a list I do not know where to start.

The answer is based on where

  • dirName: it is detected That next directory
  • Subdirectory: List of sub-directories in the current directory.
  • File List: Currently Directory of Files Directory.

Can not be done by extinction, because instead of us, we move from enumerate to a deep copy of the list so that the counter i < / Code> should be left after deletion, while the original list is modified.

I have not tried to do this, so do not trust this 100%.

Open the OS module for the # oswalk function # set the directory that you want to start from RootDir = '.' In Oswalk (rootDir) for dirName, subdirList, fileList: print for file for fname ('found directory:% s'% dirName): print ('\ t% s'% fname) i, elem inversion (list (Compute (subdirList [:]): If the "[" in AMM: del.badder list [i]

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -