In Windows you have to have drive letter in path.
Here a quick test i have also rewritten code using 3.6 and
Here a quick test i have also rewritten code using 3.6 and
f-string
.import os import shutil path = "E:/1py_div/foo/" file_name = os.listdir(path) folder_name = ['image', 'text'] for file_type in folder_name: if not os.path.exists(f'{path}{file_type}'): os.makedirs(f'{path}{file_type}') for files in file_name: if '.txt' in files and not os.path.exists(f'{path}text/{files}'): shutil.move(f'{path}{files}', f'{path}text/{files}') elif '.jpg' in files and not os.path.exists(f'{path}image/{files}'): shutil.move(f'{path}{files}', f'{path}image/{files}')