Python 文件路径

Python 文件路径

import os
import sys
strSelfPath = sys.argv[0]
print(strSelfPath)
strDir, strFullName = os.path.split(strSelfPath)
print(strDir, strFullName)
strName, strExtension = os.path.splitext(strFullName)
print(strName, strExtension)
strNameNew = strName + 'Copy'
strSelfPathNew = os.path.join(strDir, strNameNew + strExtension).replace('\', '/')
print(strSelfPathNew)
strSelfPathNew = "\"%s\"" % strSelfPathNew # windows系统上处理有空格的文件路径的问题
print(strSelfPathNew)

猜你喜欢

转载自www.cnblogs.com/dailycode/p/11955415.html