参考代码

  1. import os
  2. file_path = "/var/www/project/logs/projectpom.log"
  3. (filepath,tempfilename) = os.path.split(file_path)
  4. (filename,extension) = os.path.splitext(tempfilename)
  5. # filepath 文件路径
  6. # tempfilename 文件名(全)
  7. # filename 文件名
  8. # extension 文件后缀、扩展名

REF

  1. import os
  2. file_path = "/var/www/project/logs/projectpom.log"
  3. (filepath,tempfilename) = os.path.split(file_path)
  4. (filename,extension) = os.path.splitext(tempfilename)
  5. print("文件路径 ",filepath)
  6. print("文件名(全) ",tempfilename)
  7. print("文件名 ",filename)
  8. print("文件后缀 ",extension)

image.png

https://www.cnblogs.com/lutt/p/12115755.html