OS module - provides an interface to make calls to the operating system

#_author:"ai_XZP_master"
 #date: 2018/1/28 #Provide
 an interface for calling the operating system
 
 
import os print (os.getcwd()) #Get the current working directory # os.chdir(r'C:\Users') # print(os.getcwd()) # print(os.chdir("dirname")) # Change the working directory of the current script; equivalent to cd under the shell # print(os.curdir) #Return to the current directory : ('.') # os.makedirs('abc\\alex\\alvin') # os.makedirs('dirname1 /dirname2') # Multi-layer recursive directory can be generated # os.removedirs('abc\\alex\\alvin') # os.removedirs('dirname1/dirname2')# If the directory is empty, delete it and recurse to the top The first-level directory, if it is also empty, delete it, and so on # os.mkdir('dirname') # os.mkdir('dirname\\xzp') # os.rmdir('dirname\\xzp') #r 'G:'r is a native string # dirs = os.listdir(r'G:\Python\Day18') # print(dirs) # os.remove('_init_')# Can only delete files but not folders # os.rename('ww','www') # os.rename('os_module','abc')# abc and abc.txt are two files # info=os.stat('.\\abc') #Get file / directory information # print(info.st_size)#File size # print(info) s=os.sep print (s) #Output OS-specific path separators # 'C:%sKuGou%sCache'%s # '\r\n' # '\n' # '\r' # print(os.pathsep)#; # # print(os.system("dir")) # print(os.path.abspath('./abc'))# returns the normalized absolute path of path # s=os.path.split(r'C:\KuGou\Cache')# will path 分割成目录和文件名二元组返回 # print(s) print (os.path.dirname( 'C:\KuGou\Cache' )) # os.path.dirname(_file_file)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325568623&siteId=291194637