新聞中心
Python編程語(yǔ)言是計(jì)算機(jī)語(yǔ)言中常用的語(yǔ)言,以下的文章就是介紹在Python編程語(yǔ)言中使用os.listdir()函數(shù)來(lái)獲得目錄中的相關(guān)內(nèi)容的介紹,如果你對(duì)其相關(guān)的實(shí)際操作有興趣的話,你就可以觀看以下的文章。

Python編程語(yǔ)言如何獲得目錄中的內(nèi)容
在Python中可以使用os.listdir()函數(shù)獲得指定目錄中的內(nèi)容。其原型如下所示。
- os.listdir(path)
其參數(shù)含義如下。path 要獲得內(nèi)容目錄的路徑。以下實(shí)例獲得當(dāng)前目錄的內(nèi)容。
- >>> import os
- >>> os.listdir(os.getcwd())
獲得當(dāng)前目錄中的內(nèi)容
- ['dde.pyd', 'license.txt', 'Pythonwin.exe',
'scintilla.dll', 'win32ui.pyd', 'win32uiole.pyd',
'pywin']
如何用Python編程語(yǔ)言創(chuàng)建目錄
在Python中可以使用os.mkdir()函數(shù)創(chuàng)建目錄。其原型如下所示。
- os.mkdir(path)
其參數(shù)含義為。 path 要?jiǎng)?chuàng)建目錄的路徑。以下的實(shí)例將在E:\book目錄下創(chuàng)建temp目錄。
- >>> import os
- >>> os.mkdir('E:\\book\\temp')
使用os.mkdir創(chuàng)建目錄
刪除目錄
在Python中可以使用os.rmdir()函數(shù)刪除目錄。其原型如下所示。
- os.rmdir(path)
其參數(shù)含義如下。path 要?jiǎng)h除的目錄的路徑。以下實(shí)例刪除E:\book\temp目錄。
- >>> import os
- >>> os.rmdir('E:\\book\\temp')
刪除目錄需要說(shuō)明的是,使用os.rmdir刪除的目錄必須為空目錄,否則函數(shù)出錯(cuò)。以上的內(nèi)容就是對(duì)Python編程語(yǔ)言如何獲得目錄中的內(nèi)容,創(chuàng)建目錄,還有如何用Python編程語(yǔ)言刪除目錄的相關(guān)內(nèi)容的介紹。
新聞名稱(chēng):Python編程語(yǔ)言獲的目錄內(nèi)容及創(chuàng)建目錄的方案介紹
網(wǎng)頁(yè)地址:http://m.fisionsoft.com.cn/article/cdejoss.html


咨詢(xún)
建站咨詢(xún)
