Python Forum
Re writing poste to make sense please help me
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Re writing poste to make sense please help me
#5
In Windows you have to have drive letter in path.
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}')
Reply


Messages In This Thread
RE: Re writing poste to make sense please help me - by snippsat - Mar-31-2018, 11:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Can anyone make sense of this? steve_shambles 7 3,302 Apr-19-2020, 11:22 AM
Last Post: steve_shambles
  These boolean statements don't make sense? Athenaeum 6 5,117 Oct-03-2017, 03:34 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020