Importos.pathpathhomevameidocfile.txt print (OS. path. basename (path) # query the file name print (OS. path. dirname (path) # query the directory infoos contained in the path. path. split (path) # split the path into two parts: file name and directory... import OS. path
Path = '/home/vamei/doc/file.txt'
Print (OS. path. basename (path) # query the file name contained in the path
Print (OS. path. dirname (path) # query the directories contained in the path
Info = OS. path. split (path) # split the path into two parts: file name and directory.
Print (info)
Path2 = OS. path. join ('/', 'home', 'vamei', 'Doc', 'file1.txt ') # Use the directory name and file name to form a path string. the string is spliced and output: /home \ vamei \ doc \ file1.txt
P_list = [path, path2]
Print (OS. path. commonprefix (p_list) # query the common parts of multiple paths
OS. path. normpath (path) # Remove redundancy in the path. For example, '/home/vamei/...' is converted to '/home'
Print (OS. path. exists (path) # Query whether a file exists
Print (OS. path. getsize (path) # query the file size
Print (OS. path. getatime (path) # query the last file read time
Print (OS. path. getmtime (path) # query the last file modification time
Print (OS. path. isfile (path) # whether the path points to a regular file
Print (OS. path. isdir (path) # whether the path points to a directory file