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)

posted @ 2017-11-08 13:40  云原生生态圈  阅读(236)  评论(0编辑  收藏  举报