os.path.split, changing file name with out compromising the Path

后端 未结 1 1873
猫巷女王i
猫巷女王i 2021-02-10 03:59

i have followed Python get file name and change & save it in variable. which work fine and change the file name as required.

but now i am facing problem with path w

相关标签:
1条回答
  • 2021-02-10 04:42

    Extract the directory from the full file path, and later add it back.

    path, filename = os.path.split(docfile)
    filename = os.path.splitext(filename)[0]
    newfilename = 'ok_%s.txt' % filename
    newpath = os.path.join(path, newfilename)
    
    0 讨论(0)
提交回复
热议问题