File Operations in the OS module:
OS module attributes
Linesep is a string used to split rows in a file.
A string used to separate the file path name.
Pathsep is a string used to separate file paths.
String name of the current working directory of curdir
Pardir (current working directory) parent directory string name
1. Rename: OS. Rename (old, new)
2. Delete: OS. Remove (file)
3. List the files in the directory: OS. listdir (PATH)
4. Get the current working directory: OS. getcwd ()
5. Change the working directory: OS. chdir (newdir)
6. Create a multilevel Directory: OS. makedirs (R "C: \ Python \ test ")
7. Create a single directory: OS. mkdir ("test ")
8. Delete multiple directories: OS. removedirs (R "C: \ Python") # delete all empty directories in the last directory of the given path.
9. delete a single directory: OS. rmdir ("test ")
10. Get file attributes: OS. Stat (file)
11. Modify the File Permission and timestamp: OS. chmod (file)
12. Execute the operating system command: OS. System ("dir ")
13. Start a new process: OS .exe C (), OS .exe CVP ()
14. Execute the program in the background: osspawnv ()
15. Terminate the current process: OS. Exit (), OS. _ exit ()
16. Separated file name: OS. Path. Split (R "C: \ Python \ hello. py") --> ("C: \ Python", "Hello. py ")
17. separation Extension: OS. path. splitext (R "C: \ Python \ hello. PY ") --> (" C: \ Python \ hello ",". PY ")
18. Obtain the path name: OS. Path. dirname (R "C: \ Python \ hello. py") --> "C: \ Python"
19. Get the file name: OS. Path. basename (R "R: \ Python \ hello. py") --> "Hello. py"
20. Determine whether the file exists: OS. Path. exists (R "C: \ Python \ hello. py") --> true
21. Determine whether the path is absolute: OS. Path. isabs (R ". \ Python \") --> false
22. Check whether the directory is OS. Path. isdir (R "C: \ Python") --> true
23. Determine whether the file is: OS. Path. isfile (R "C: \ Python \ hello. py") --> true
24. Determine whether the file is a linked file: OS. Path. islink (R "C: \ Python \ hello. py") --> false
25. Get file size: OS. Path. getsize (filename)
26. *******: OS. ismount ("C: \") --> true
27. Search all files in the directory: OS. Path. Walk ()
Detailed source reference: http://www.jb51.net/article/28905.htm