Python Forum

Full Version: rename and add desire "_date" to end of file name before extention
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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.