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)
    
    
  • 相关阅读:
    cJSON库源码分析
    cJSON 使用详解
    day23
    day22
    作业21
    day21
    作业20
    day20
    作业
    day19
  • 原文地址:https://www.cnblogs.com/xuelong3/p/7803635.html
Copyright © 2011-2022 走看看