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)
  • 相关阅读:
    unityshader学习笔记3
    unityshader学习笔记2
    unityshader学习笔记1
    AssetBundle资源打包与加载
    lua学习笔记4--XLua
    lua学习笔记3--lua与c#交互
    lua学习笔记2--table
    cocos2dx-android-添加64位编译
    lua学习笔记1--基础语法
    使用青花瓷(charles)抓包
  • 原文地址:https://www.cnblogs.com/jona-test/p/13295574.html
Copyright © 2011-2022 走看看