viewing file names and files paths
>>> import os>>> url = ' http://images.cnitblog.com/i/311516/201403/020013141657112.png ' >> > filename = os.path.basename (URL) >>> filepath = os.path.dirname (URL) >>> filename ' 020013141657112.png ' >>> filepath ' http://images.cnitblog.com/i/311516/201403 ' >>>
(Os.path.realpath ()) (Os.path.dirname (Os.path.realpath ())) (Os.path.basename (Os.path.realpath ()))
Print (Os.listdir (dirname)) # displays only the file name and directory name under that directory, does not contain files in subdirectories, and defaults to the directory where the current file resides
import os# os.walk () traverse all Files under Folder # Os.walk () get three sets of data (RootDir, Dirname,filnames ) def file_path (File_dir): For root, dirs, files in Os.walk (File_dir): print (Root, end= ") # current directory path PR Int (dirs, end= ") # All subdirectories under the current path print (files) # All non-directory sub-files under the current directory