1.getcwdd () to get the application's current working directory
# Getcwd () Gets the application's current working directory Import os Print (os.getcwd ())
2.chdir (path) to change the current working directory
os.chdir ( " E: \\ " ) # change the working directory Print (os.getcwd ())
3.listdir (path = ',') are listed in the current folder
print(os.listdir())
4.mkdir (path) create folders
os.mkdir("test")
5.makedirs (path) to create multi-level directory
os.makedirs(r".\aa\bb\cc")
6.remove () and rmdir () removedirs () to delete files, delete files, folders, and delete multi-level folder
os.remove("1.txt") os.rmdir("b") os.removedirs(r"a\b")
7.rename () Rename
os.rename("a","b")
8.walk (top) top traversing all subdirectories parameter specifies the path, and returns a result triples.
# Walk ( "path") traverse parameter specifies that all subdirectories for i in os.walk ( " BaiduYunDownload " ): Print (i)
Function name
|
Instructions
|
basename(path) | Remove the directory path, file name alone returns |
dirname(path) | Remove the file name, directory path returned alone |
join(path1[, path2[, ...]]) | The path1, path2 departments packet combining a pathname |
split(path) | Split the file name and path, return (f_path, f_name) tuples. If full use of the directory, it will also last a separate directory as the file name, and does not determine whether file or directory exists |
splitext(path) | Separate file name and extension, return (f_name, f_extension) tuples |
getsize(file) | Returns the specified file size in bytes |
getatime(file) | Returns the most recent file access time (floating-point number of seconds, the available time module gmtime () or localtime () function conversion) |
getctime(file) | Returns the creation time of the specified file (float number of seconds, the available time module gmtime () or localtime () function conversion) |
getmtime(file) | Returns the latest file modification time (floating-point number of seconds, the available time module gmtime () or localtime () function conversion) |
The following is the function returns True or False
|
|
exists(path) | Analyzing the specified path (file or directory) exists |
isabs(path) | It determines whether the specified path is an absolute path |
isdir(path) | Determining whether there is a specified path is a directory and |
isfile(path) | And determining whether there is a specified path is a file |
islink(path) | And the specified path is determined whether there is a symbolic link |
ismount(path) | Determining whether there is a specified path is a mount point and the root directory |
Smefaile (Pthl, Pht2) | Analyzing two paths path1 and path2 point to the same file |