Python's OS module

Source: Internet
Author: User

#!/usr/bin/env Python3
# _*_ Coding:utf-8 _*_

Import OS

OS.GETCWD ()
#os. ChDir (' path ')
Print (Os.curdir)
Print (Os.pardir)
#os. Makedirs (r "C:\t1\t2\t3") #递归生成目录
# Os.removedirs (r "C:\t1\t2\t3") #递归删除空目录
# Os.mkdir (r "C:\t1") #生成单级目录
# Os.rmdir (r "C:\t1") #删除单级空目录
# Os.listdir (r "C:\cptest") #列出指定目录下的所有文件和子目录
# Os.remove () #删除一个文件
# os.rename ("Oldname", "NewName") #重命名一个目录或文件
Print (Os.stat (r) C:\cptest\CT_ROOTS. XML ")) #获取文件/directory information
Print (OS.SEP) #输出操作系统特定的路径分隔符
Print (OS.LINESEP) #行分隔符
Print (OS.PATHSEP) #输出用于分割文件路径的字符串
Print (Os.name) #当前操作系统的平台
# Os.system () #运行shell命令
# print (Os.environ) #获取系统环境变量
# Os.path.abspath (path) #返回绝对路径
# Print (Os.path.split (r "C\absa")) #将path分割成目录和文件名
# os.path.dirname (path) #返回path的目录
# Print (Os.path.basename (r "C:\ABCS\DDP")) #返回path最后的文件名
# os.path.exists (path) #如果path存在, returns True, otherwise false
# os.path.isabs (path) #如果是绝对路径, returns True
# os.path.isfile (path) #如果path是一个存在的文件, returns True, otherwise false
# os.path.isdir (path) #如果path是一个存在的目录, returns True, otherwise false
# Os.path.join (path1,path2) #将多个路径组合
Print (Os.path.getatime (r "C:\cptest\BDMReportPlus.dll") #返回path所指向的文件或者目录的最后存取时间
Print (Os.path.getmtime (r "C:\cptest\BDMReportPlus.dll")) #返回path所指向的文件或者目录的最后修改时间

Python's 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.