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

后端 未结 1 1870
猫巷女王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)
提交回复
热议问题