예제 #1
0
# Update date
count = 0
zero_count = 0
for file in all_files1:
    count += 1
    full_filename = file.get_full_path()
    path, fn = os.path.split(full_filename)
    date_taken = file.get_date_taken()

    if "0000" in date_taken:
        zero_count += 1

    year, month, day, dt = ImageUtils.get_dt_captured_split()

    creation_date_str = "{0}-{1}-{2}".format(year, month, day)

    new_file = fn.replace("images_", "")
    new_file = new_file.replace("_.", ".")
    new_file = new_file.replace("~", "")
    new_file = new_file.replace("....", ".")
    new_file = "{0}_{1}".format(creation_date_str, fn)
    if FileUtils.does_file_exist(new_file, path) is not True:
        print(path + new_file)
        os.rename(full_filename, path + new_file)
    else:
        print(new_file + " file exists")

    print("Filename: {0} date: {1}".format(fn, date_taken))

print("Total count: {0} Zero Count: {1}".format(count, zero_count))
            new_file = new_file.replace("Pictures to sort and save", "IMG")
            new_file = new_file.replace("_.", ".")
            new_file = new_file.replace(" ", "_")

            new_file = orig_date + "_" + new_file

            while "__" in new_file:
                new_file = new_file.replace("__", "_")

            if problem_files_str is not "":
                problem_files.append(
                    problem_files_str +
                    "Date 1: {0} and Date 2: {1} Filename: {2} New_File: {3}".
                    format(date_taken[:4], orig_date[:4], file, new_file))

            while FileUtils.does_file_exist(new_file, root + os.sep) is True:
                print("Dup: " + new_file)
                new_file = FileUtils.add_suffix(new_file, "1")

            full_new_file = root + os.sep + new_file

            # os.rename(full_filename, full_new_file)
            files_log.write("Old: " + full_filename + "\n")
            files_log.write("New: " + full_new_file + "\n")

        count += 1

for f in problem_files:
    log_file.write(f + "\n")

log_file.write("Total count: {0} Zero Count: {1} \n".format(count, zero_count))
예제 #3
0
 def test_does_file_exist(self):
     self.assertFalse(FileUtils.does_file_exist("fakefile", " "))
     self.assertFalse(FileUtils.does_file_exist(2, " "))
     self.assertTrue(
         FileUtils.does_file_exist(
             "IMG_0001.jpg", "/Users/paulottley/Desktop/MomsDadsPhotos/"))
예제 #4
0
        word_year = ""
        if m_year is not None:
            word_year = m_year.group().replace("_", "")

        m_day = re.search(r"_\d{1,2}_", word_date)

        word_day = ""
        if m_day is not None:
            word_day = m_day.group().replace("_", "")
            if int(word_day) < 10:
                word_day = "0" + word_day

        new_fn = fn.replace(
            "0000-00-00_" + word_date,
            "{0}-{1}-{2}_".format(word_year, month_num, word_day))
        new_fn = new_fn.replace("__", "_")
        print("File: {0} New: {1}".format(fn, new_fn))
        if FileUtils.does_file_exist(new_fn, path):
            print("Files exists! {0}".format(new_fn))
        else:
            os.rename(line, path + os.sep + new_fn)
"""
for root, dirs, files in os.walk(START_DIR):
    for file in files:
        new_file = file.replace(",", "")
        if file != new_file:
            print("File: {0} New File: {1}".format(file, new_file))
            os.rename(root + os.sep + file, root + os.sep + new_file)
"""
batch_input.close()