Python writes a tool for all subdirectory in the specified directory

xiaoxiao2021-03-06  40

These days, because of the need, I just learned Python, so I wrote such a thing. Very rough, but fortunately, I am compelling my job. Oh. Its function is to list all subfolders in the specified directory. It can also be specified that these folders must be included in the specified extension file. For example, you can list the C: / Directory, all the directory containing .c, .h files. At this time, only need to enter such two parameters. : Input File path: C: / Input File type: .c, .h huh, this thing is really rough, but I hope someone can use it, then I am really happy.

# ShowdirFrom Os.Path Import * Import StringImport Osdef Walkdir (Spath, Mode): Path = OS.ListDir (Spath) DIR, File = [], [] for i in pat: if isdir (Join (SPATH, I)): Dir.Append (i) Else: file.append (i) if mode == ['']: Print Spath Else: for J in file: Findout = 0 for K in Mode: IF J [-Len (K):] == K: Print Spath Findout = 1 Break IF Findout: Break for K in Dir: Walkdir (Join (Spath, K), Mode) Def isfiletype (MODE): Return 1 Def showdir (): print 'Welcome ...' SPATH = Raw_INPUT ("Input File Path:"): Print "File Path Error!" Return Mode = Raw_Input ("Input File Type:") If not isfiletype (mode): Print "File Type Error! "Return Print 'Files List ...' smode = string.split (Mode, ',') Walkdir (spath, smode) showdir ()

转载请注明原文地址:https://www.9cbs.com/read-68448.html

New Post(0)