zoukankan      html  css  js  c++  java
  • os模块的常用方法使用

    '''
    @Descos模块的常用方法使用
    os.getcwd()
    os.path.exists(dir)
    os.listdir(dir)
    os.path.join(dir, file)
    os.path.isfile(fullpath)
    os.path.isdir(fullpath)
    os.path.dirname(dir) 可用于跳转到【上一级】目录
    '''

    import os

    class OsModules:
    dirs = "F:\cs_auto\DisposaAssetsTest"

    def osPathExists(self, dir):
    print("当前路径:", os.getcwd())
    # 当前文件所在路径:
    casepath = os.path.dirname(__file__)
    print("casepath===", casepath)
    # 当前路径的上一级路径:
    basepath = os.path.dirname(casepath)
    print("basepath===", basepath)
    if os.path.exists(dir):
    files = os.listdir(dir)
    print(dir, "中包含的目录有:", files)
    fullpath = os.path.join(dir, files[0])
    print("目录中第一个文件(或目录)的完整路径是:", fullpath)
    if os.path.isfile(fullpath):
    print(fullpath, "是一个文件")
    elif os.path.isdir(fullpath):
    print(fullpath, "是一个目录")
    else:
    print(fullpath, "啥也不是")
    else:
    print(dir, "不是个目录")

    if __name__ == '__main__':
    OsModules.osPathExists("self", OsModules.dirs)
  • 相关阅读:
    卡尔曼滤波的原理与思想
    什么是端口
    什么是ICD文件
    USB口,串口,以太网口简介
    Linux基本操作笔记
    网络营销学习路线图
    读书推荐:2017 第一期
    又见Bug
    如何请教别人问题?
    圆桌问答 (2017 第一季)
  • 原文地址:https://www.cnblogs.com/jona-test/p/13295574.html
Copyright © 2011-2022 走看看