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
#2
I am writing a program to use on not android and windows in order to reorganize files into folders by there extension and delete empty folders.

At the moment it runs for android and works great but does not work for windows.

I'm fairly new to python and would very much like an explanation as to why it doesn't work and how I can change it.

Thank you for reading this so far.
Here is my code so far
import os
import shutil

#change the pathway were to sort
path ="/internalsharedstorage/downloads/"
name = os.listdir(path)
folder_name = ['image','text','exe','mp3','mp4','apk','pdf','zip','rar','sav']
for x in range(0,10):
    if not os.path.exists(path+folder_name[x]):
        os.makedirs(path+folder_name[x])
# movement of files 
for files in name:
    if '.pdf' in files and not os.path.exists(path+'pdf/'+files):
        shutil.move(path+files, path+'pdf/'+files)
        
    elif '.zip' in files and not os.path.exists(path+'zip/'+files):
        shutil.move(path+files, path+'zip/'+files) 
        
    elif '.exe' in files and not os.path.exists(path+'exe/'+files):
        shutil.move(path+files, path+'exe/'+files)

    elif '.jpeg' in files and not os.path.exists(path+'image/'+files):
        shutil.move(path+files, path+'image/'+files)
        
    elif '.txt' in files and not os.path.exists(path+'text/'+files):
        shutil.move(path+files, path+'text/'+files)
        
    elif '.mp3' in files and not os.path.exists(path+'music/'+files):
        shutil.move(path+files, path+'music/'+files)
        
    elif '.sav' in files and not os.path.exists(path+'save/'+files):
        shutil.move(path+files, path+'sav/'+files)
        
    elif '.rar' in files and not os.path.exists(path+'rar/'+files):
        shutil.move(path+files, path+'rar/'+files)
        
    elif '.mp4' in files and not os.path.exists(path+'mp4/'+files):
        shutil.move(path+files, path+'mp4/'+files)

    elif '.apk' in files and not os.path.exists(path+'apk/'+files):
        shutil.move(path+files, path+'apk/'+files)
else:        
    print ('cant be moved')
Cheers guys
Reply


Messages In This Thread
Re writing poste to make sense please help me - by Nearrivers - Mar-31-2018, 07:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Can anyone make sense of this? steve_shambles 7 3,358 Apr-19-2020, 11:22 AM
Last Post: steve_shambles
  These boolean statements don't make sense? Athenaeum 6 5,178 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