Python路径操作
作者:互联网
Python路径操作
import os import shutil def testPath(): sourcePath = os.getcwd() file = os.path.join(sourcePath,"frame_BAR_offset_16.bdf") #拼接路径 print(file) #C:\Users\admin\Desktop\Temp\frame_BAR_offset_16.bdf folder,fileBaseName = os.path.split(file) print(folder) #C:\Users\admin\Desktop\Temp print(fileBaseName) #frame_BAR_offset_16.bdf str1,suffix = os.path.splitext(file) print(str1) #C:\Users\admin\Desktop\Temp\frame_BAR_offset_16 print(suffix) #.bdf print(os.path.dirname(file)) #C:\Users\admin\Desktop\Temp print(os.path.basename(file)) #frame_BAR_offset_16.bdf print(file.split(".")[-1]) #bdf newFolder = os.path.join(sourcePath,"folder") if os.path.exists(newFolder): shutil.rmtree(newFolder) #删除文件夹 os.mkdir(newFolder) #创建文件夹
标签:bdf,BAR,Python,路径,file,path,print,操作,os 来源: https://www.cnblogs.com/wjw1340/p/14191694.html