Python Road 27-os Module

Source: Internet
Author: User

import os# gets the current directory print (OS.GETCWD ()) #改变当前目录os. ChDir ("D:\learn_python3") #生成单层目录os. mkdir ("1") #删除单层目录, The directory cannot have file Os.rmdir ("1") #生成多层目录os. Makedirs ("1\\test") #删除多层目录os. Removedirs ("1\\test") #列出指定目录下的所有文件和子目录, including hidden files, and print Os.listdir () #重命名文件/directory Os.rename ("One", "1") #获取文件/Catalog information print (Os.stat ("test.py")) #输出操作系统特定的路径分隔符print (os.sep ) #输出当前平台使用的行终止符print (OS.LINESEP) #输出用于分割文件路径的字符串print (os.pathsep) #输出字符串指示当前使用平台print (os.name) #运行shell命令, Direct display of the Os.system ("Free -m") #获取系统环境变量print (Os.environ) #返回path规范化的绝对路径print (Os.path.abspath ("D:\learn_python3\ Practice \ \ ")) #将path分割成目录和文件名二元组返回print (Os.path.split (" D:\learn_python3\ exercise \\test.py ")) #返回path的目录print (os.path.dirname ("D:\learn_python3\ Practice \\test.py")) #返回path最后的文件名print (Os.path.basename ("D:\learn_python3\ exercise \\test.py")) #如果path存在, returns True if path does not exist, returns Falseprint ( Os.path.exists ("D:\learn_python3\ Exercise")) #如果path是绝对路径, return to Trueprint (Os.path.isabs ("Learn_python3")) #如果path是一个存在的文件, Returns True. Otherwise returns Falseprint (Os.path.isfile ("D:\learn_python3\ exercise \\1.py")) #如果path是一个存在的目录, returns True. Otherwise, return Falseprint (OS.Path.isdir ("D:\learn_python3\ Exercise")) #将多个路径组合后返回, parameters before the first absolute path are ignored for print (Os.path.join ("d:\\", "learn_python\\", "practice") #返回path所指向的文件或者目录的最后存取时间, print in Timestamps (Os.path.getatime ("test.py")) #返回path所指向的文件或者目录的最后修改时间, print in timestamp form ( Os.path.getmtime ("test.py"))


This article is from the "Eight Miles" blog, so be sure to keep this source http://5921271.blog.51cto.com/5911271/1897311

Python Road 27-os Module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.