This script, once added to the Windows Scheduler, automatically creates a backup of your Google Chrome bookmarks.import shutilimport osimport datetimedef setup():    print ('Enter your Chrome bookmark directory.')    print ('Standard one is: C:\\Users\\<USER>\\AppData\\Local\\Google\\Chrome\\User Data\\Default')    bookmarkfolder = input('> ')    print ('Enter the folder you want to save the backup files in.')    print ('For example: C:\\Users\\<USER>\\Desktop\\Chrome Bookmarks')    backupfolder = input('> ')    with open('user.txt', 'w') as txt:        txt.write(bookmarkfolder + '\n' + backupfolder)    copy()def copy():    userList = []    date = datetime.date.today()    with open('user.txt', 'r') as txt:        for line in txt:            userList.append(line.strip())    shutil.copy(userList[0] + '\\Bookmarks', userList[1])    try:        os.rename('Bookmarks', 'Bookmarks' + str(date).replace('-',''))    except WindowsError:        os.remove('Bookmarks' + str(date).replace('-',''))        os.rename('Bookmarks', 'Bookmarks' + str(date).replace('-',''))def checksetup():    with open('user.txt', 'r') as setupfile:        setupfile.seek(0)        for line in setupfile:            if '\\' in line:                copy()            else:                setup()checksetup()
Auto backup Chrome bookmarks
python;beginner;python 3.x;scheduled tasks;google chrome
The logic isn't so easy to follow, especially since the loops in copyand checksetup imply that there are more lines, but really there willbe only two at most, the bookmark and backup folder.  I'd suggest makingthat more obvious and avoiding for line in file: in case you only everwant to have a fixed number of lines in that file.The code also doesn't work with no user.txt file present, so somemore checks and error handling are necessary to handle that case aswell.Some of the paths and other constructs are duplicated, I'd always try tominimise the amount of duplication, so with that in mind, consider moreconstants and variables to extract common code.The .seek(0) in checksetup isn't necessary with mode 'r'; if youopen a file (for reading) you'll already be at the start; however, themode should probably be 'a+' anyway to create the file if it doesn'texist.If you don't like the escapes all the time, consider using the rsyntax instead.Use the if __name__ == __main__: ... construct as is customary,that way this file could be imported and used without runningchecksetup as is it would currently.Python typically uses lower case names with underscores between words,c.f. PEP8.For the date formatting use the strftime method instead to get thedesired output directly.The setup method could use some more error checks, e.g. whether thefolders exist.The user.txt file is opened three times in the worst case; itwould also be better to pass the two values necessary for the scriptin the script as function arguments instead of parsing the file sooften; I'll leave that be for the moment though.  In general I'd saythat copy should have the signaturecopy(bookmark_directory, backup_directory) and should be called withthe values from the file instead of parsing it.After all that you can also look into command line arguments usinge.g. argparse forparsing options, that way users won't have to deal with pesky manualinput instead of reusing the shell completion (for specifying thefolders).So, it should look more like this perhaps:import shutilimport osimport datetimeSETUP_FILE = 'user.txt'def setup():    print ('Enter your Chrome bookmark directory.')    print (r'Standard one is: C:\Users\<USER>\AppData\Local\Google\Chrome\User Data\Default')    bookmarkfolder = input('> ')    print ('Enter the folder you want to save the backup files in.')    print (r'For example: C:\Users\<USER>\Desktop\Chrome Bookmarks')    backupfolder = input('> ')    with open(SETUP_FILE, 'w') as txt:        txt.write(bookmarkfolder + '\n' + backupfolder + '\n')    copy()def copy():    with open(SETUP_FILE, 'r') as txt:        user_list = [line.strip() for line in txt]    shutil.copy(user_list[0] + r'\Bookmarks', user_list[1])    new_name = datetime.date.today().strftime('Bookmarks%Y%m%d')    try:        os.rename('Bookmarks', new_name)    except WindowsError:        os.remove(new_name)        os.rename('Bookmarks', new_name)def checksetup():    try:        with open(SETUP_FILE, 'r') as txt:            txt.seek(0)            line = txt.readline()        if '\\' in line:            copy()        else:            setup()    except FileNotFoundError:        setup()if __name__ == __main__:    checksetup()