简体   繁体   中英

Python - How would I require a user to create a folder on their desktop?

I have an application that includes a GUI. When the user clicks 'Submit' I would like to check and make sure that they have created a folder on their desktop with a specific name. If they have not created this folder on their desktop I would like to prompt them with a popup informing them to create this folder. I know how to create popups but how would I go about checking that they have created this folder? Lets call this folder 'example'.

I have tried:

desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 
   'Desktop').replace('\\', '/')

   if 'Example' not in desktop:
            sg.popup("Please create a folder named 'Example' on Desktop and 
            resubmit")
            quit()

This is a small example of doing this :D

import os
def makeDir():
    folder="exemple"
    print os.path.expanduser("~") # path to the home directory of the user
    path_to_user=os.path.expanduser("~")
    path_to_desktop=os.path.join(path_to_user,"Desktop") #we are now in Desktop folder
    if os.path.isdir(os.path.join(path_to_desktop,folder)):
        return False #if exists ....
    else:
        #os.mkdir(os.path.join(path_to_desktop,folder)) #if not, make dir without asking or 
        return True

if makeDir()==False:
    print "Exists!"
    #continue to do smt
else:
    print "Make that dir!" # make the require

makeDir()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM