os模組常用方法

2022-06-19 11:21:12 字數 879 閱讀 3030

將當前資料夾下的檔案

"wt.txt

"重新命名為"

wtt.txt"。

os.rename(

"wt.txt

", "

.\\tmh\\wtt.txt")

將當前資料夾下的檔案

"wt.txt

"複製到當前資料夾的子資料夾"

tmh"

中。os.remove(

".\\tmh\\wtt.txt")

刪除當前資料夾的子資料夾

"tmh

"中的檔案"

wtt.txt"。

os.rmdir(

".\\tmh")

刪除當前資料夾的子資料夾

"tmh"。

os.mkdir(

"d:\\tmh")

在d盤根目錄下建乙個資料夾

"tmh"。

os.chdir(

"d:\\tmh")

把"d:\\tmh

"設定為當前工作目錄。

os.getcwd()

返回當前工作目錄。

listdir(path)的功能是返回path目錄下的檔案和目錄列表。對該列表進行遞迴遍歷可以遍歷資料夾path下的所有檔案和資料夾。

os.path 模組下方法

os模組常用方法

os模組 os.name 輸出字串指示正在使用的平台。如果是window 則用 nt 表示,對於linux unix使用者,它是 posix result os.name print result os.getcwd 函式得到當前工作目錄 就是你的程序所工作的目錄 即當前python指令碼工作的目錄...

OS 模組常用方法

os.getcwd 返回當前工作目錄 os.chdir path 改變當前工作目錄 os.listdir path 列出指定目錄下的所有的資料夾和檔案 os.chmod path,mode 更改許可權 os.mkdir path mode 以數字mode的mode建立乙個名為path的資料夾 os....

OS模組常用方法

os模組 os模組就是對作業系統進行操作,使用該模組必須先導入模組 importos getcwd 獲取當前工作目錄 當前工作目錄預設都是當前檔案所在的資料夾 result os.getcwd print result chdir 改變當前工作目錄 os.chdir home sy result o...