Feb-07-2020, 05:34 AM
I have a list of file. I am going to change the file name regarding to the modified date in below format. original file name:
2019-11-26_#001.tws
2019-11-26_#002.tws
2019-11-26_#004.tws ...
new name:
2019-11-26_#1.1.tws
2019-11-26_#1.2.tws
2019-11-26_#2.1.tws
...
the important point is; its possible the sequence of the filename would be different in some cases, i.e I did not have number 3 but the number 4 should be renamed to (count as) 2.1.
I can use the below code for renaming, but I dont know How to use loop to cover all name.
2019-11-26_#001.tws
2019-11-26_#002.tws
2019-11-26_#004.tws ...
new name:
2019-11-26_#1.1.tws
2019-11-26_#1.2.tws
2019-11-26_#2.1.tws
...
the important point is; its possible the sequence of the filename would be different in some cases, i.e I did not have number 3 but the number 4 should be renamed to (count as) 2.1.
I can use the below code for renaming, but I dont know How to use loop to cover all name.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import os import shutil from os import path import os import shutil from os import path def main(): if path.exists( "2019-11-26_#001.tws" ): src = path.realpath( "2019-11-26_#001.tws" ); os.rename( '2019-11-26_#001.tws' , '2019-11-26_#1.1.tws' ) if __name__ = = "__main__" : main() |