The method to use:
Import OS
Os.listdir ('/etc/'): Lists all files and directories under the specified directory
Os.path.isdir ('/etc/'): Determines whether it is a directory, returns a Boolean value
Os.path.isfile ('/etc/passwd '): Determines whether a file is returned with a Boolean value
Os.path.join ('/etc ', ' passwd '): Connect two paths
Cases:
#!/usr/bin/python
Import Sys
Import OS
def print_files (path):
Lsdir=os.listdir (PATH)
Dirs=[i for I in Lsdir if Os.path.isdir (os.path.join (path, i))]
Files=[i for I in Lsdir if Os.path.isfile (os.path.join (path, i))]
If files:
For f in Files:
Print Os.path.join (path, F)
If dirs:
For D in dirs:
Print_files (Os.path.join (path, D))
Print_files (Sys.argv[1])
This article is from "The Miracle Teenager" blog, please be sure to keep this source http://raffaelexr.blog.51cto.com/8555551/1783018
Recursively list all files in a directory