Exemplo n.º 1
0
def CheckIfFileExists(pth_to_check):
    global _write_mode

    if os.path.isfile(pth_to_check):
        print("Default file name --> ", pth_to_check, ", already exists.")
        print("   Enter option: ")
        print("   'write (w)'            : to OVERWRITE file")
        print("   'append (a)'           : to APPEND file")
        print("   new_file_name: to create NEW file")
        user_in = input("--> ").lower()

        if (any(val == user_in.lower()
                for val in Utils._write_modes.keys())) or any(
                    val == user_in.lower()
                    for val in Utils._write_modes.values()):
            if user_in == 'a' or user_in == 'append':
                CsvHand.SetSaveMode('append')

            if user_in == 'w' or user_in == 'write':
                CsvHand.SetSaveMode('write')
                CsvHand.StartNewFile()
        else:
            #create new file given name
            Utils.SetMarkedFileName(user_in)
            while os.path.isfile(Utils.GetSavePath()):
                print("The file: " + Utils.GetSavePath() + " already exists.")
                Utils.SetMarkedFileName(input("Enter new file name: "))
            CsvHand.StartNewFile()

    else:
        CsvHand.StartNewFile()

    print("--> Marked files will be stored at location: " +
          (Utils.GetSavePath()))
    input("--> Press ENTER key")