0

I was wondering how to get my script to return to the beginning if “Y” or “y” is pressed? I tried making it a function, then calling that function if the “IF” statement returns “Y” or “y”, but that does not work. Any help would be appreciated, thanks.

 import os
 path = os.getcwd() #Working/active directory

 filenames = os.listdir(path)

 print "**Rename Active Directory File(s)**\n"

 CurName = raw_input ("Current Name: ")
 NewName = raw_input ("New Name: ")`

 def Ren():
     for filename in filenames:
     os.rename(os.path.join(path, filename), os.path.join(path, filename.replace(CurName, NewName)))

 Final = raw_input('\nPress Enter to Exit or \"Y" to Restart!:\n ')

 if Final == 'Y' or 'y':
     Ren()
MRG123
  • 123
  • 3
  • 12
  • `if Final.lower() == 'y':` – furas Jul 08 '14 at 19:12
  • BTW: there is the `PEP8` rule: use lowercase in variable name and function name. So use `cur_name`, `new_name`, `ren()`, `final`. Uppercase is reserved for class name. – furas Jul 08 '14 at 19:16

0 Answers0