1 import os 2 # os.mkdir('stt') #Create a folder 3 # os.rmdir('stt') #Delete a folder 4 # os.makedirs('stt/tts') #Create nested files Folder 5 # os.removedirs('stt/tts') #If the directory is empty, delete it, and recurse to the previous directory, if it is also empty, delete it, and so on 6 7 # print(os.getcwd( )) #Print file path 8 # os.chdir('..') #Go to the previous level 9 # print(os.getcwd()) 10 11 # print(os.listdir()) #Print the consent directory in list form File under 12 #print(os.stat('a.txt')) #st_size indicates how many bytes the file occupies st_atime indicates the time when the file was last viewed st_mtime indicates the time when the file was last modified st_ctime indicates the time when the file was created 13 # a = os.stat ('a.txt') 14 # print(a.st_size) 15 16 # print(os.sep) #Output the path separator of the current system 17 # os.rename('oldname','newname') #Rename the file 18 # print(os.pathsep) #Output the string used to split the file path; under win; under Linux: 19 # print(os.environ) #Get system environment variables 20 # print(os.path.split( 'a.txt')) #Split path into directory and filename 2-tuple return 21 #print(os.path.dirname(path)) #Return the directory of path. In fact, it is the first element of os.path.split(path) 22 # print(os.path.basename(path)) #Return the last file name of path. If path ends with / or \, then it will return a null value. That is, the second element of os.path.split(path) 23 24 # # Record 25 26 os.getcwd() Get the current working directory, that is, the directory path where the current python script works 27 os.chdir( " dirname " ) Change the current Script working directory; equivalent to cd 28 under the shell os.curdir Returns the current directory: ( ' . ' ) 29 os.pardir Gets the parent directory string name of the current directory: ( ' .. ' ) 30 os.makedirs( ' dirname1/ dirname2 ') can generate multiple recursive directories _ _ _ _ _ ' ) to generate a single-level directory; equivalent to mkdir dirname 33 os.rmdir( ' dirname ' ) in the shell to delete a single-level empty directory, if the directory is not empty, it cannot be deleted, and an error is reported; equivalent to rmdir dirname 34 os.listdir( ' dirname ' ) list all files and subdirectories in the specified directory, including hidden files, and print them in a list35 os.remove() delete a file36 os.rename( " oldname " , " newname " ) rename a file/ catalog 37 os.stat( ' path/filename ' ) Get file/ directory information 38 os.sep Output operating system-specific path separators, " \\ " under win, " / " under Linux 39 os.linesep Output current platform use The line terminator is " \t\n " under win, " \ n " under Linux 40 os.pathsep output the string used to split the file path; under win: 41 os.name output character The string indicates the currently used platform. win-> ' nt ' ; Linux-> ' posix ' 42 os.system( " bash command " ) run the shell command and display 43 directly os.environ Get system environment variables 44 os.path.abspath(path) Returns the normalized absolute path of path 45 os.path.split(path) Splits path into directory and file name tuples Return 46 os.path.dirname( path) returns the directory of path. In fact, it is the first element of os.path.split(path) 47 os.path.basename(path) returns the last file name of path. If path ends with / or \, then it will return a null value. That is, the second element of os.path.split(path) 48 os.path.exists(path) If path exists, return True; if path does not exist, return False 49 os.path.isabs(path) If path is absolute path, returns True 50 os.path.isfile(path) Returns True if path is an existing file. Otherwise returns False 51 os.path.isdir(path) Returns True if path is an existing directory. Otherwise, return False 52 os.path.join(path1[, path2[, ...]]) Return after combining multiple paths, parameters before the first absolute path will be ignored 53 os.path.getatime(path) Returns the last access time of the file or directory pointed to by path 54 os.path.getmtime(path) Returns the last modification time of the file or directory pointed to by path