檔案目錄操作函式概述

2021-08-30 12:29:52 字數 868 閱讀 7919

在python中,python遞迴中的檔案操作主要來自os模組,主要方法如下:

os.listdir(dirname):列出dirname下的目錄和檔案

os.getcwd():獲得當前工作目錄

os.curdir:返回當前目錄('.')

os.chdir(dirname):改變工作目錄到dirname

os.path.isdir(name):判斷name是不是乙個目錄,name不是目錄就返回false

os.path.isfile(name):判斷name是不是乙個檔案,不存在name也返回false

os.path.exists(name):判斷是否存在檔案或目錄name

os.path.getsize(name):獲得檔案大小,如果name是目錄返回0l

os.path.abspath(name):獲得絕對路徑

os.path.normpath(path):規範path字串形式

os.path.split(name):分割檔名與目錄

(事實上,如果你完全使用目錄,它也會將最後乙個目錄作為檔名而分離,

同時它不會判斷檔案或目錄是否存在)

os.path.splitext():分離檔名與副檔名

os.path.join(path,name):連線目錄與檔名或目錄

os.path.basename(path):返回檔名

os.path.dirname(path):返回檔案路徑

os.remove(dir) #dir為要刪除的資料夾或者檔案路徑

os.rmdir(path) #path要刪除的目錄的路徑。需要說明的是,

使用os.rmdir刪除的目錄必須為空目錄,否則函式出錯。

php檔案目錄操作函式

1 建立目錄 mkdir bool mkdir string pathname int mode bool recursive resource context mkdir path to my dir 0777 成功返回true,失敗返回false 2 判斷檔案是否存在 file exist bo...

檔案概述 檔案操作

檔案概述 php裡面檔案包含 目錄dir 和 檔案file 兩種 檔案操作 一,檔案屬性 1,獲取檔案型別 filetype images 2,判斷是否是目錄 is dir 3,判斷是否是檔案 is file 4,檔案上次訪問時間 fileatime 5,檔案建立時間 filectime 6,檔案修...

常見檔案 目錄 路徑操作函式

bool winapi deletefile in lpctstr lpfilename 刪除乙個檔案 int shfileoperation lpshfileopstruct lpfileop 刪除很多檔案 bool winapi removedirectory in lpctstr lppath...