python學習筆記(19) 常用模組--OS模組
os.getcwd() #獲取當前目錄
os.chdir() #開啟目錄,記得加r
os.curdir #返回當前目錄os.chdir('.')
os.pardir #獲取當前目錄的父目錄字串名 ('..')
os.makedirs()
os.removedirs() #刪除多個空目錄
os.mkdir() #找不到上層報錯
os.rmdir() #只能刪除空的
os.listdir() #以列表開啟,包括隱藏檔案
os.remove()
os.rename()
os.stat() #獲取檔案/目錄資訊
os.sep #輸出系統特定的路徑分隔符,win為‘\\’,linux是'/'
os.linesep #輸出當前平臺的行終止符,win是\t\n linux是\n
os.pathsep #輸出當前平臺路徑分隔符,win為; linux為: (環境變數)
os.name #輸出當前平臺 win ->nt linux->posix
os.system() #執行shell命令
os.popen().read #有返回值
os.environ 獲取系統環境變數
os.path.abspath(path) #返回規範化的絕對路徑
os.path.split(path) #將path分割成目錄和檔名二元組返回
os.path.dirname(path) #返回path目錄
os.path.basename(path) #返回path最後的檔名,如果以/\結尾則返回空
os.path.exists()
os.path.isabs()
os.path.isfile()
os.path.isdir()
os.path.join() #將多個路徑組合後返回,第一個絕對路徑之前的引數將被忽略
os.path.getatime() #訪問時間
os.path.getmtime() #修改時間
os.path.getsize() #資料夾的大小不準確