zoukankan      html  css  js  c++  java
  • Python OS Module

    # Licensed Materials - Property of xuelong
    # Pythonlife
    # ScriptName: fileops.vianet
    # Author: xuelong
    # Data: 2017-Nov-08-12-52
    # IDE: PyCharm Community Edition
    #coding:utf8
    
    import os
    
    curr_dir=os.getcwd()    #the file location
    list_dir=os.listdir(curr_dir)   #list all file in current file location,return a list type
    # list_dir.append("ioops.py")
    # os.remove(curr_dir+"/stringconstants.py") # in fact. remove a file from curr_dir.
    # os.removedirs(r"%s" % curr_dir)   #remove multi dirs.
    # os.path.exists(curr_dir+"/stringconstants.py")  #return true or false
    # print(os.path.isdir(curr_dir))  #return true or false
    # print(os.path.isabs(curr_dir))  #return true or false,whether the path is absolute path.
    file=curr_dir+"/handle.py"
    new_file=file+"new"
    # print(os.path.isfile(file))  # return true or false. whether the argument is file or not.
    # print(os.path.split(file)) # return file path and file name.this is a tuple type.
    # print(os.path.splitext(file)) #split expand name.this is a tuple type.
    print(os.path.dirname(file))    #equal os.getcwd()
    print(os.path.basename(file))   #equal os.path.split(file)[1]
    # os.getenv()
    # os.putenv()
    # os.system()
    # os.linesep
    # os.name
    # os.rename(file,new_file)
    # os.makedirs(r"/opt/python/script")
    # os.mkdir("test")
    # os.stat(file)
    # os.chmod(file)
    print(os.path.getsize(file))
    # print(curr_dir)
    # print(list_dir)
    
    
  • 相关阅读:
    SqlServer卡慢解决办法
    His表(简化)
    解决Oracle数据库空间不足问题
    获取select下拉框选中的的值
    使用编辑器Sublime
    Angularjs中的$filter
    Angularjs 的Controlleras 和$scope
    在html页面中实现代码的高亮显示
    Angularjs的ui-router
    TML5之Canvas
  • 原文地址:https://www.cnblogs.com/xuelong3/p/7803635.html
Copyright © 2011-2022 走看看