0

I'm trying to call different functions based on the user input in the Tkinter window for the user_input3 variable.

Basically, in case the user inputs c, il calls def creation(), m calls def lastmodified() and a calls def lastaccessed()

Problem is, it goes in an infinite loop asking for the user_input3 string in the while loop.

How can I resolve this?

Also, for some reason I can't get to use match(input): etc. AKA match pattern in my code, this is why I'm using the method in my code...

Thanks for the help and here is my code:

def creation():
    lst.sort(key=os.path.getctime)
    num = 1
    for line in lst:
        dst = newpath + name + str(num) + suffix
        rename(line, dst)
        num += 1

def lastmodified():
    lst.sort(key=os.path.getmtime)
    num = 1
    for line in lst:
        dst = newpath + name + str(num) + suffix
        rename(line, dst)
        num += 1

def lastaccessed():
    lst.sort(key=os.path.getatime())
    num = 1
    for line in lst:
        dst = newpath + name + str(num) + suffix
        rename(line, dst)
        num += 1

root = tkinter.Tk()

filez = tkinter.filedialog.askopenfilenames(parent=root, title='Select files to rename (must be all of the same type!)')

lst = list(filez)

suffix = pathlib.Path(lst[1]).suffix

root = tkinter.Tk()
root.geometry("400x240")

ROOT = tkinter.Tk()
ROOT.withdraw()

USER_INP = simpledialog.askstring(title="File Names", prompt="Name your files:")

username = getpass.getuser()

name = USER_INP

USER_INP2 = simpledialog.askstring(title="Folder Name", prompt="Name your folder:")

foldername = USER_INP2

newpath = r'/Users/' + username + '/Desktop/' + foldername + '/'
if not os.path.exists(newpath):
    os.makedirs(newpath)

user_input3 = simpledialog.askstring(title="Mode",
                                         prompt="Write: c to order by creation, m by last modified, a by last accessed")

while user_input3 != 'c' or user_input3 != 'm' or user_input3 != 'a':
    user_input3 = simpledialog.askstring(title="Mode",
                                         prompt="Write: c to order by creation, m by last modified, a by last accessed")

if user_input3 == 'c':
    creation()
elif user_input3 == 'm':
    lastmodified()
elif user_input3 == 'a':
    lastaccessed()
Traceback (most recent call last):
  File "/Users/michy/PycharmProjects/Order_My_Files/Order_My_Files.py", line 110, in <module>
    lastaccessed()
  File "/Users/michy/PycharmProjects/Order_My_Files/Order_My_Files.py", line 47, in lastaccessed
    lst.sort(key=os.path.getatime())
TypeError: getatime() missing 1 required positional argument: 'filename'

0 Answers0