標籤:360安全瀏覽器 import sandbox adobe set storm map 判斷 pat
1.合并路徑
os.path.join("c:\\music\\ap\\0","mav.mp3")‘c:\\music\\ap\\0\\mav.mp3‘
2.尋找使用者目錄
os.path.expanduser("~")‘C:\\Users\\Administrator‘
3.分割路徑名和檔案名稱
os.path.split("c:\\music\\ap\\羊皮的狼.MP3")(‘c:\\music\\ap‘, ‘羊皮的狼.MP3‘)#元組tuple
4.通過定義元組來分開路徑名和檔案名稱
>>> (filepath,filename)=os.path.split("c:\\music\\ap\\羊皮的狼.MP3")>>> filepath‘c:\\music\\ap‘>>> filename‘羊皮的狼.MP3‘
5.分開檔案名稱和副檔名
>>> filename‘羊皮的狼.MP3‘>>> (shortname,extensionname)=os.path.splitext(filename)>>> shortname‘羊皮的狼‘>>> extensionname‘.MP3‘
6.列出路徑下的這一級的所有檔案夾和檔案
os.listdir("d:\\mysql\\")[‘lib‘, ‘my 2017-12-10 1949.ini.bak‘, ‘my 2017-12-10 1953.ini.bak‘, ‘my.ini‘]
>>> os.listdir("c:\\")
[‘$360Section‘, ‘$Recycle.Bin‘, ‘1805-18 SUWLARKJ14 入殼點焊機 (原理圖) A0.pdf‘, ‘1805-18 SUWLARKJ14 惠鵬博 (伺服線由超高柔更換為高柔).pdf‘, ‘360SANDBOX‘, ‘acadminidump.dmp‘, ‘AX NF ZZ‘, ‘Boot‘, ‘bootmgr‘, ‘Config.Msi‘, ‘Documents and Settings‘, ‘Downloads‘, ‘Drivers‘, ‘DRMsoft‘, ‘FeigeDownload‘, ‘Google‘, ‘hangcha.pdf‘, ‘HWUpdates‘, ‘Intel‘, ‘kingdeeplm‘, ‘MSOCache‘, ‘OEMSF‘, ‘offline_FtnInfo.txt‘, ‘pagefile.sys‘, ‘Program Files‘, ‘Program Files (x86)‘, ‘ProgramData‘, ‘QMDownload‘, ‘Skypee‘, ‘SSE138folder‘, ‘System Volume Information‘, ‘System32Folder‘, ‘TEMP‘, ‘Users‘, ‘uwscan_n.ini‘, ‘WeldWave.ini‘, ‘Windows‘, ‘_ISTMP1.DIR‘]
7.判斷一個路徑是檔案還是目錄
>>> [f for f in os.listdir("c:\\") if os.path.isfile(os.path.join("c:\\",f))][‘1805-18 SUWLARKJ14 入殼點焊機 (原理圖) A0.pdf‘, ‘1805-18 SUWLARKJ14 惠鵬博 (伺服線由超高柔更換為高柔).pdf‘, ‘acadminidump.dmp‘, ‘bootmgr‘, ‘hangcha.pdf‘, ‘offline_FtnInfo.txt‘, ‘pagefile.sys‘, ‘uwscan_n.ini‘, ‘WeldWave.ini‘]檔案判斷>>> [f for f in os.listdir("c:\\") if os.path.isdir(os.path.join("c:\\",f))][‘$360Section‘, ‘$Recycle.Bin‘, ‘360SANDBOX‘, ‘AX NF ZZ‘, ‘Boot‘, ‘Config.Msi‘, ‘Documents and Settings‘, ‘Downloads‘, ‘Drivers‘, ‘DRMsoft‘, ‘FeigeDownload‘, ‘Google‘, ‘HWUpdates‘, ‘Intel‘, ‘kingdeeplm‘, ‘MSOCache‘, ‘Program Files‘, ‘Program Files (x86)‘, ‘ProgramData‘, ‘QMDownload‘, ‘Skypee‘, ‘SSE138folder‘, ‘System Volume Information‘, ‘System32Folder‘, ‘TEMP‘, ‘Users‘, ‘Windows‘, ‘_ISTMP1.DIR‘]檔案夾判斷
8.尋找特定的檔案
>>> os.listdir("d:\\")[‘$RECYCLE.BIN‘, ‘1.json.wmv‘, ‘1805-18 SUWLARKJ14 入殼預焊機 (IO配置表) - A0.pdf‘, ‘1805-18 suwlarkj14入殼點焊機 a0-1.bak‘, ‘1805-18 suwlarkj14入殼點焊機 a0-1.dwg‘, ‘1805-18 SUWLARKJ14入殼點焊機 A0.dwg‘, ‘1805-18瑞浦入殼點焊機 A0_2018_06_21.dwg‘, ‘1805-28 SUWLARKJ13-02 入殼預焊機FAT_改二.xlsx‘, ‘2018-關於收繳黨費的相關要求.rar‘, ‘360Downloads‘, ‘360MoveData‘, ‘360安全瀏覽器下載‘, ‘6PPM入殼預焊機‘, ‘adobe‘, ‘androidstudio‘, ‘asmpg‘, ‘BaiduYunDownload‘, ‘c#筆記‘, ‘CAD‘, ‘cat_200_300.jpg‘, ‘datastream.txt‘, ‘icon.png‘, ‘irisdata.txt‘, ‘lab.dat‘, ‘lbview‘, ‘lib‘, ‘LVS.txt‘, ‘map.txt‘, ‘masm32‘, ‘mels‘, ‘MES系統資料擷取需求表v1.05成都銀隆_雷射封口(雷射清洗).xlsx‘, ‘MFC類圖.png‘, ‘mkspecs‘, ‘mmp.txt‘, ‘mmpp.txt‘, ‘MSOCache‘, ‘mysql‘, ‘open.reg‘, ‘openok.reg - 副本.txt‘, ‘openok.reg.txt‘, ‘plugins‘, ‘pp.PNG‘, ‘py‘, ‘python‘, ‘qt‘, ‘sanliuo‘, ‘SHEET.xls‘, ‘Skypee‘, ‘solidworks‘, ‘StormMedia‘, ‘System Volume Information‘, ‘vc‘, ‘vs‘, ‘YE_Applications‘, ‘娛樂‘, ‘密封釘焊接工作台培訓表.xlsx‘, ‘嵌入式工具軟體‘, ‘工具軟體‘, ‘戶籍轉回辦理手續‘, ‘焊接條碼‘, ‘使用者目錄‘, ‘電氣專業圖紙審核自檢表FR-02-17066(1).xls‘, ‘程式規範中的錯誤.doc‘, ‘編程軟體‘, ‘自動化手冊‘, ‘西丹孚密封釘全部資料與參數‘, ‘迅雷下載‘, ‘銀隆密封釘程式規範.docx‘]>>> import glob>>> glob.glob("d:\\*.txt")[‘d:\\datastream.txt‘, ‘d:\\irisdata.txt‘, ‘d:\\LVS.txt‘, ‘d:\\map.txt‘, ‘d:\\mmp.txt‘, ‘d:\\mmpp.txt‘, ‘d:\\openok.reg - 副本.txt‘, ‘d:\\openok.reg.txt‘]
python-os模組使用