python模組之os.path,pythonos.path

來源:互聯網
上載者:User

python模組之os.path,pythonos.path

對檔案路徑的操作

 

os.path.split(p)函數返回一個路徑的目錄名和檔案名稱。

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

 

os.path.isfile()和os.path.isdir()函數分別檢驗給出的路徑是一個檔案還是目錄。

os.path.isabs(path):判斷一個路徑是否是絕對路徑

os.path.exists()函數用來檢驗給出的路徑是否真地存在

 

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

os.path.getatime(path) 返回path所指向的檔案或者目錄的最後存取時間

os.path.getmtime(path) 返回path所指向的檔案或者目錄的最後修改時間

 

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

>>> os.path.normpath('c://windows\\System32\\../Temp/')

'c:\\windows\\Temp'

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

 

os.path.basename(path):返迴文件名

os.path.dirname(path) 返回path的目錄。其實就是os.path.split(path)的第一個元素

os.path.abspath(path) 返回path正常化的絕對路徑

>>> import os.path

>>> os.path.abspath('c.py')

'/root/py/c.py'

>>> os.path.abspath('../py/c.py')

'/root/py/c.py'

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.