Python Forum
rename and add desire "_date" to end of file name before extention - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: rename and add desire "_date" to end of file name before extention (/thread-37439.html)



rename and add desire "_date" to end of file name before extention - RolanRoll - Jun-10-2022

hi I have many folders that all of them have same 4 folders( annotation,measurment,preview,support) and 2 files( manifest.saf and .pdf extention) like this:
annotation

measurement

preview

support

manifest.safe

S1A_IW_SLC__1SDV_20220316T020357_20220316T020424_042340_050C30_FC59.SAFE-report-20220316T194123.pdf

I need to rename manifest file and add "_date" (that is mentioned in pdf file name for example 20220316)in S1A_IW_SLC__1SDV_20220316T020357_20220316T020424_042340_050C30_FC59.SAFE-report-20220316T194123.pdf
then i have:

manifest_20220316.safe


RE: rename and add desire "_date" to end of file name before extention - gruntfutuk - Jun-13-2022

So where exactly are you stuck?

You might want to explore using pathlib to handle the path/folder/filenames. Good article on this lib on RealPython.com. They also cover how to rename files.