I am creating a GUI for the program that renames all the files numerically (eg. 1, 2, 3, etc) in python 3.10, Visual Studio 2022. I am receiving this error on os.rename() in the for loop -
[WinError 17] The system cannot move the file to a different disk
Here's my whole code -
from tkinter import *
import tkinter.filedialog
import os
import pathlib
window=Tk()
window.title('Hello Python')
window.geometry("300x200+10+10")
window.resizable(False, False)
window.configure(bg='white')
brackets = False
def rename():
fileNumber = 1
folderPath = tkinter.filedialog.askdirectory(parent=window, initialdir='Documents', title='Please select a folder')
for filename in os.listdir(folderPath):
fileExt = pathlib.Path(filename).suffix
filePath = folderPath + '/' + filename
if (fileExt != '.py') :
if (brackets):
os.rename(filePath, str(fileNumber) + ')' + fileExt)
else:
os.rename(filePath, str(fileNumber) + fileExt)
fileNumber += 1
lbl=Label(window, text="Welcome to rename it!", fg='black', bg='white', font=("Helvetica", 20))
lbl.place(relx = 0.5, y = 25, anchor=CENTER)
btn=Button(window, text="Rename", fg='blue', command=rename)
btn.place(x=80, y=100)
window.mainloop()
I don't want to move the files, I just want to rename them. Any help would be appreciated.