code: (using Os.listdir)
Copy the Code code as follows:
Import OS
def listfilestotxt (dir,file,wildcard,recursion):
exts = Wildcard.split ("")
Files = Os.listdir (dir)
For name in Files:
Fullname=os.path.join (Dir,name)
if (Os.path.isdir (FullName) & recursion):
Listfilestotxt (fullname,file,wildcard,recursion)
Else
For ext in exts:
if (Name.endswith (EXT)):
File.write (name + "\ n")
Break
Def Test ():
Dir= "J:\\1"
Outfile= "Binaries.txt"
Wildcard = ". txt. exe. dll. Lib"
File = open (outfile, "w")
If not file:
Print ("Cannot open the file%s for writing"% outfile)
Listfilestotxt (Dir,file,wildcard, 1)
File.close ()
Test ()
code: (using Os.walk) walk recursively to the directory and subdirectory processing, each return three items are: The current recursive directory, all subdirectories under the current recursive directory, all the files in the current recursive directory.
Copy the Code code as follows:
Import OS
def listfilestotxt (dir,file,wildcard,recursion):
exts = Wildcard.split ("")
For root, subdirs, files in Os.walk (dir):
For name in Files:
For ext in exts:
if (Name.endswith (EXT)):
File.write (name + "\ n")
Break
if (not recursion):
Break
Def Test ():
Dir= "J:\\1"
Outfile= "Binaries.txt"
Wildcard = ". txt. exe. dll. Lib"
File = open (outfile, "w")
If not file:
Print ("Cannot open the file%s for writing"% outfile)
Listfilestotxt (Dir,file,wildcard, 0)
File.close ()
Test ()