So I need to write a function that if a file exists, it will change the file name by sequentially adding integers, starting with 1, to the base file name (the part that does not include the file extension). so if the filename is hello.dat, then it will return hello1.dat and if it exists, then hello2.dat, and so on. If it does not exist it'll stop.
I understand that I have to use a while loop and os.path.isfile. My teacher suggested rsplit and I don't understand it. I've googled it, and read many sites, and it's so unclear to me! it says something about sep, maxsplit, delimiter? I don't understand.
Ok, so the split was for separating the file from the folder and separating the filename from its extension. Thanks for clearing that up :)
I have a question though,
when I didn't separate the file from its folder I got:
which makes sense, but when I inputed the code that you wrote for separating it I got:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
File "C:\Users\Golden Hands\Documents\assignment 2.py", line 19, in okfilename
file_path = path.abspath(file_path)
UnboundLocalError: local variable 'file_path' referenced before assignment
how can this be fixed?
For Each ctrl As Control In Me.Controls("pnlMainPanel").Controls
If ctrl.GetType Is GetType(System.Windows.Forms.Panel) Then
For Each subCtrl As Control In ctrl.Controls
If subCtrl.GetType Is GetType(System.Windows.Forms.TextBox) Then
If subCtrl.GetType Is ...