I am new to python. I tried to search for answers but I cannot find a exact match to my question. I am trying to move all non-Excel files to another folder. However, there is an error when trying to move a .pbix file. I wonder if there are only limited number of filetypes supported by shutil.move() and os.rename() in moving files. And, are there any workarounds? Thank you.
UPDATE: The error is PermissionError. Actually, when I checked now the target folder, the file is transferred but the original file is retained.
Here is my sample code:
files = os.listdir(os.getcwd())
for f in files:
try:
data = pd.read_excel(f) # importing the file
except:
shutil.move("{}".format(f), r".\\Non_Excel_Files\{}".format(f))
It is now working. Thanks to the suggestion of S3DEV.
files = os.listdir(os.getcwd())
for f in files:
if os.path.splitext(f)[1] != ".xlsx":
shutil.move("{}".format(f), r".\\Non_Excel_Files\{}".format(f))