檔案 資料夾的相關操作

2021-08-21 06:06:09 字數 595 閱讀 8169

有些時候,需要對檔案進行重新命名、刪除等一些操作,python的os模組中都有這麼功能

os模組中的rename()可以完成對檔案的重新命名操作

rename(需要修改的檔名, 新的檔名)

import os

os.rename("畢業**.txt", "畢業**-最終版.txt")

os模組中的remove()可以完成對檔案的刪除操作

remove(待刪除的檔名)

import os

os.remove("畢業**.txt")

import os

os.mkdir("張三")

import os

os.getcwd()

import os

os.chdir("../")

import os

os.listdir("./")

import os

os.rmdir("張三")

Windows,Linux資料夾相關操作

參考 判斷資料夾是否存在 在windows環境下標頭檔案為 include在linux環境下標頭檔案為 include下述函式在windows和linux環境下均可使用 int access const char filename,int accessmode 該函式功能為確定檔案或資料夾的訪問許可...

php資料夾的相關操作

php獲取資料夾大小 function dirsize path if is dir path.item closedir handle return sum 注意用的時候記得每次 要清0,要不然會累加 php建立資料夾 建立資料夾 param string dirname return strin...

iOS 檔案以及資料夾相關操作

檔案相關操作 返回解壓成功或失敗.需要使用到ziparchive srcfile 待解壓檔案全路徑 destfile 解壓檔案全路徑.bool unzipfile nsstring srcfile tofile nsstring destfile withdeleteflag bool bdel z...