python的檔案和目錄操作
阿新 • • 發佈:2019-01-10
一 獲得當前路徑
1、程式碼1
>>>import os
>>>print('Current directory is ',os.getcwd())
Current directory is D:\Python36
Current directory is E:\python\work
三 建立目錄>>> os.listdir (os.getcwd()) ['DLLs','Doc','include','Lib','libs','LICENSE.txt','NEWS.txt','PyOpenGL-wininst.log','python.exe','python3.dll','python36.dll','pythoncom36.dll','pythonw.exe','pywin32-wininst.log','pywintypes36.dll','RemovePyOpenGL.exe','Removepywin32.exe','Scripts','tcl','Tools','vcruntime140.dll']
>>>import os
>>> os.mkdir('temp')
>>> os.rmdir('temp')
>>> os.path.isdir('E:\\python')
True
>>> os.path.isfile('E:\\python\\work\\test.py')
True