예제 #1
0
 def test_move_file(self):
     self.assertFalse(
         FileUtils.move_file(
             "/Users/paulottley/Desktop/MomsDadsPhotos/IMG_0001.jpg",
             "/Users/paulottley/Desktop/SortTarget/images/",
             "IMG_0001.jpg"))
     self.assertFalse(
         FileUtils.copy_file(
             "/Users/paulottley/Desktop/MomsDadsPhotos/IMG_0001.jpg",
             "/Users/paulottley/Desktop/SortTarget/frog/", "IMG_0001.jpg"))
예제 #2
0
# @author Paul Ottley
# @copyright 2017
# File used to start the FilesSorter launch
import os

from app import FileUtils

STR_DIR3 = r"/Volumes/MyBook2TB/Backups/Library"
STR_DIR4 = r"/Users/paulottley/Google Drive/MomsDadsPhotos"

TGT_DIR1 = r"/Users/paulottley/Desktop/SortTarget"

for root, dirs, files in os.walk(STR_DIR3):
    for file in files:
        ext = FileUtils.get_file_type(file)
        FileUtils.move_file(root + os.sep + file,
                            STR_DIR3 + os.sep + ext + os.sep, file)

# Step 1 Walk the directory

# Step 2 Determine filetype by extension

# Step 3 Move to appropriate folder
예제 #3
0
count = 0
zero_count = 0
missing_filename_dt = 0
missing_embed_dt = 0
mismatched_dt = 0
dot_file_count = 0

log = open(LOG_FILE, "w")

print("Checking for Dot files...")
for root, dirs, files in os.walk(STR_DIR1):
    for file in files:
        full_filename = root + os.sep + file
        if "." is file[0]:
            print("Moving..." + full_filename)
            FileUtils.move_file(full_filename,
                                r"/Volumes/Elements2TB/Backups/Trash/", file)
            dot_file_count += 1
print("Number of dot files: {0}".format(dot_file_count))

# for file in all_files1:
for root, dirs, files in os.walk(STR_DIR1):
    for file in files:
        count += 1

        tgt_dir = root + os.sep
        filename = file
        full_path = root + os.sep + file
        orig_date = ImageUtils.get_original_date(full_path)

        line = ""
예제 #4
0
    for file in files:

        target_dir = root

        tgt_folder = FileUtils.get_file_category(file)

        try:
            dt, str_dt = ImageUtils.get_dt_from_name(file)
            if dt is None:
                print("Zero or None: " + file)
                target_dir = "{0}{1}{2}{3}".format(
                                                    root,
                                                    os.sep,
                                                    "no_date",
                                                    os.sep)
            else:
                target_dir = "{0}{1}{2}{3}{4}{5}".format(
                                                    root + os.sep,
                                                    tgt_folder + os.sep,
                                                    dt.year,
                                                    os.sep,
                                                    dt.month,
                                                    os.sep)

            FileUtils.move_file(root + os.sep + file, target_dir, file)

        except Exception as err:
            print("Date failed on: {0} with error: {1}".format(file, err))


# Open file log with write privileges
files_log = open(FILES_BATCH, "w")
log_file = open(LOG_FILE, "w")

start_time = datetime.datetime.now()
log_file.write("Correct Date started at {0} \n".format(start_time))

for root, dirs, files in os.walk(STR_DIR1):
    for file in files:

        full_filename = root + os.sep + file

        if "." is file[0]:
            print("Moving..." + full_filename)
            FileUtils.move_file(full_filename,
                                r"/Volumes/MyBook2TB/Backups/Trash/", file)

        else:
            date_taken = ImageUtils.get_dt_from_name(file)[0]
            orig_datetime = ImageUtils.get_original_date(full_filename)[0]

            if orig_datetime is not None:
                orig_date = orig_datetime.split(" ")[0]
            else:
                orig_date = "0000-00-00"
            new_file = file

            # TODO Figure out if there is a need to reconcile date_taken and orig_date

            if "0000" in orig_date:
                if file[0] is not ".":
예제 #6
0
    def move_files(all_files):
        print("Total files to move {0}".format(len(all_files)))

        for x in all_files:
            FileUtils.move_file(x.get_full_path(), x.get_tgt_dir(),
                                x.get_tgt_filename())
예제 #7
0
STR_DIR3 = r"/Volumes/Elements2TB/Backups/Pictures/images"
# STR_DIR3 = r"/Volumes/MyBook2TB/Backups/SortTarget"
TGT_DIR1 = r"/Volumes/MyBook2TB/Backups/Library/videos/Cleanup"

for root, dirs, files in os.walk(STR_DIR3):
    for file in files:
        if "...." in file:
            new_file = file.replace("...", "")
            print(root + os.sep + new_file)
            os.rename(root + os.sep + file, root + os.sep + new_file)
        if "---" in file:
            new_file = file.replace("---", "-")
            print(root + os.sep + new_file)
            os.rename(root + os.sep + file, root + os.sep + new_file)
        if "0000-00-00" in file:
            FileUtils.move_file(file, root + os.sep + "zeros" + os.sep, file)
            """
            new_file = file.replace("0000-00-00", "0000-00-00")
            if FileUtils.does_file_exist(new_file, root + os.sep) is not True:
                print(root + os.sep + new_file)
                os.rename(root + os.sep + file, root + os.sep + new_file)
            else:
                print(new_file + "file exists")

        m = re.search(r"20\d{2}-\d{2}-\d{1}\D", file)

        # Pull full date from name
        if m is not None:
            print(file + " file exists")
        if " " in file:
            new_file = file.replace(" ", "")