Module - OS

import them

#Some operations on the operating system

# os.chmod("filename", permission number) #Change permissions, only for Linux
(#1 execute #2 write #4 read)

# print(os.chdir("../day5"))#Change the current directory

# print(os.getcwd()) #Get the current working directory

# print(os.makedirs("nhy/python"))#Create a folder recursively, automatically create a parent directory when the parent directory does not exist

# print(os.mkdir("zll/huangrong"))#Create a folder

#makedirs When creating a folder, if the parent directory does not exist, it will automatically create the parent directory for you

# print(os.removedirs("nhy/python"))#Recursively delete empty directories

# print(os.rmdir("test2"))#Delete the specified folder
#Can only delete empty directories

# os.remove("test2")#Only delete files

# os.rmdir('test2') #Can only delete folders


# print(os.listdir('e:\\'))#List all files in a directory

# os.rename("test","test1")#重命名

# print(os.stat("x.py"))#Get file information

print(os.sep)#The path separator of the current operating system
# day5+os.sep+x.py

# print(os.linesep)#The newline character of the current operating system
# \n \r\n

# print(os.pathsep)#The separator of each path in the environment variable of the current system, linux is:, windows is;

# print(os.environ)#Environment variables of the current system

# print(os.name)#The current system name Windows systems are all nt linux are all posix

# res = os.system('ipconfig') #Execute operating system commands, but get no results

#res = os.popen('ipconfig').read() #You can get the result of command execution

# __file__ #Get the absolute path to the current file
# print(os.path.abspath('.'))#Get the absolute path
# print(os.path.abspath(__file__))#Get the absolute path to the current file

# print(os.path.split("/usr/hehe/hehe.txt"))#Split path and file name

# print(os.path.dirname("e:\\syz\\ly-code"))#Get the parent directory, get its parent directory

# print(os.path.basename("e:\\syz\\ly-code\\a.txt"))#Get the last level, if it is a file, display the file name, if it is a directory, display the directory name

# print(os.path.exists(r"E:\syz\ly-code\day6"))#Does the directory/file exist?

# print(os.path.isabs("../day5"))#Determine whether it is an absolute path

# print(os.path.isfile("xiaohei.py")) #To
determine whether it is a file, 1. The file must exist 2. It must be a file

# print(os.path.isdir("e:\\syz1"))#Is it a path and whether the directory exists

# size = os.path.getsize('x.py') #Get the size of the file #Cannot
exceed 2m
# print(size)

# print(os.path.join("root",'hehe','mysql','a.sql'))#Spliced ​​into a path, automatically recognizes the path separator

# for abs_path,dir,file in os.walk(r'E:\syz\ly-code\day6'): #Get the contents of the directory os.listdir()
# #
# print(abs_path,dir,file)
# abs_path The absolute path of the current loop
# All folders under the dir directory [ ]
# All files under the file directory []

Guess you like

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