0

Before posting this, i just refer the link for renaming files in bulk, which is very useful to me while renaming a file from a given folder.

Before renaming, i do a validation check on file name from a excel sheet, if file present then rename it to it's respective name

enter image description here

I wrote a small code as below

for i in range(3, max_rw + 1):
 oCell = oSht.cell(column = 1, row = i)
 oCellr = oSht.cell(column = 2, row = i)
 nm = oCell.value
 renm = oCellr.value
 files = os.listdir(fldpth)


  for file in files:
     if nm in file:
        os.rename(os.path.join(fldpth, file), os.path.join(fldpth, renm+'.svg'))

But the output of the file in some place misleading as like below

  1. Overridding previous value for below condition

    if nm in file:

    Script might be doing global search, that mean in excel i have many items in name of "contact" i.e Contact Selected [Row#3, as shown], Contact unselected[Row#4, as shown] & many more including Contact[Row#253]

    If i am doing search from Row#3 to 12 then result is correct

    Contact unselected RENAMED TO Contact-unselected

    If i do full search to max_column then result is wrong

    Contact unselected RENAMED TO contact

  2. Underscore is missing in many places like

    Group selected RENAMED TO Group Selected

    History selected RENAMED TO History Selected

    Map selected RENAMED TO Map Selected

Sreekiran A R
  • 3,123
  • 2
  • 20
  • 41
Kapi
  • 43
  • 8

0 Answers0