Skip to content

Instantly share code, notes, and snippets.

@wotori
Last active April 15, 2025 11:04
Show Gist options
  • Save wotori/a16ad7d89c1610cae31cd1d5cf9f7fd4 to your computer and use it in GitHub Desktop.
Save wotori/a16ad7d89c1610cae31cd1d5cf9f7fd4 to your computer and use it in GitHub Desktop.

Revisions

  1. wotori revised this gist Apr 15, 2025. 2 changed files with 57 additions and 49 deletions.
    49 changes: 0 additions & 49 deletions copy.py
    Original file line number Diff line number Diff line change
    @@ -1,49 +0,0 @@
    import os
    import shutil
    from datetime import datetime
    from tqdm import tqdm

    source = "/from"
    dest = "/to"

    dist_set = set()
    file_count = 0

    # Count the total number of files to copy
    for root, subdir, files in os.walk(source):
    files = list(filter(lambda x: x[-4:] != ".xmp", files))
    file_count += len(files)

    dist_set = set()
    file_count = 0

    # Count the total number of files to copy
    for root, subdir, files in os.walk(source):
    files = list(filter(lambda x: x[-4:] != ".xmp", files))
    file_count += len(files)

    # Create progress bar
    with tqdm(total=file_count, desc="Copying files") as pbar:
    for root, subdir, files in os.walk(source):
    files = list(filter(lambda x: x[-4:] != ".xmp", files))
    for file in files:
    file_path = os.path.join(root, file)
    timestamp = int(os.path.getmtime(file_path))
    date = datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d') # %H:%M:%S
    year, month, day = date.split("-")
    cp_file_path = os.path.join(dest, year, month, day)
    if cp_file_path not in dist_set:
    dist_set.add(cp_file_path)
    os.makedirs(cp_file_path, exist_ok=True)

    file_check = os.path.join(cp_file_path, file)
    if not os.path.exists(file_check):
    shutil.copy2(file_path, cp_file_path)
    sidecar = f"{file_path}.xmp"
    if os.path.exists(sidecar):
    shutil.copy2(sidecar, cp_file_path)

    # Update progress bar and display the current file being copied and the destination
    pbar.set_postfix(file=file, destination=cp_file_path)
    pbar.update(1)
    print("done!")
    57 changes: 57 additions & 0 deletions copy_media.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    import os
    import shutil
    from datetime import datetime
    from tqdm import tqdm

    source = "/mnt/raid/iPhoneDima/iphone_dump_25_04_14"
    dest = "/mnt/raid/iPhoneDima/"

    file_list = []

    # Gather list of all files to copy (excluding .xmp)
    for root, subdir, files in os.walk(source):
    files = [f for f in files if not f.endswith(".xmp")]
    for file in files:
    full_path = os.path.join(root, file)
    file_list.append(full_path)

    # Create progress bar for copying
    with tqdm(total=len(file_list), desc="Copying files") as pbar:
    for file_path in file_list:
    timestamp = int(os.path.getmtime(file_path))
    date = datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d')
    year, month, day = date.split("-")
    cp_file_path = os.path.join(dest, year, month, day)
    os.makedirs(cp_file_path, exist_ok=True)

    file = os.path.basename(file_path)
    dest_file = os.path.join(cp_file_path, file)

    if not os.path.exists(dest_file):
    shutil.copy2(file_path, cp_file_path)
    sidecar = f"{file_path}.xmp"
    if os.path.exists(sidecar):
    shutil.copy2(sidecar, cp_file_path)

    pbar.set_postfix(file=file, destination=cp_file_path)
    pbar.update(1)

    # Verification step
    missing_files = []
    for file_path in file_list:
    timestamp = int(os.path.getmtime(file_path))
    date = datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d')
    year, month, day = date.split("-")
    cp_file_path = os.path.join(dest, year, month, day)
    file = os.path.basename(file_path)
    dest_file = os.path.join(cp_file_path, file)

    if not os.path.exists(dest_file):
    missing_files.append(dest_file)

    if not missing_files:
    print("✅ All files copied successfully!")
    else:
    print("❌ Some files were not copied:")
    for f in missing_files:
    print(" -", f)
  2. wotori revised this gist Aug 4, 2023. 1 changed file with 15 additions and 4 deletions.
    19 changes: 15 additions & 4 deletions copy.py
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,14 @@
    dist_set = set()
    file_count = 0

    # Count the total number of files to copy
    for root, subdir, files in os.walk(source):
    files = list(filter(lambda x: x[-4:] != ".xmp", files))
    file_count += len(files)

    dist_set = set()
    file_count = 0

    # Count the total number of files to copy
    for root, subdir, files in os.walk(source):
    files = list(filter(lambda x: x[-4:] != ".xmp", files))
    @@ -27,10 +35,13 @@
    if cp_file_path not in dist_set:
    dist_set.add(cp_file_path)
    os.makedirs(cp_file_path, exist_ok=True)
    shutil.copy2(file_path, cp_file_path)
    sidecar = f"{file_path}.xmp"
    if os.path.exists(sidecar):
    shutil.copy2(sidecar, cp_file_path)

    file_check = os.path.join(cp_file_path, file)
    if not os.path.exists(file_check):
    shutil.copy2(file_path, cp_file_path)
    sidecar = f"{file_path}.xmp"
    if os.path.exists(sidecar):
    shutil.copy2(sidecar, cp_file_path)

    # Update progress bar and display the current file being copied and the destination
    pbar.set_postfix(file=file, destination=cp_file_path)
  3. wotori revised this gist Aug 4, 2023. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions copy.py
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,11 @@
    from datetime import datetime
    from tqdm import tqdm

    sd_card = "/Volumes/sd_card"
    dest = "/Volumes/mnt/raid/"
    source = "/from"
    dest = "/to"

    dist_set = set()
    file_count = 0

    # Count the total number of files to copy
    for root, subdir, files in os.walk(source):
  4. wotori revised this gist Aug 4, 2023. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions copy.py
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@
    if os.path.exists(sidecar):
    shutil.copy2(sidecar, cp_file_path)

    # Update progress bar
    # Update progress bar and display the current file being copied and the destination
    pbar.set_postfix(file=file, destination=cp_file_path)
    pbar.update(1)

    print("done!")
  5. wotori revised this gist Aug 4, 2023. 1 changed file with 29 additions and 14 deletions.
    43 changes: 29 additions & 14 deletions copy.py
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,35 @@
    import os
    import shutilil
    import shutil
    from datetime import datetime
    from tqdm import tqdm

    sd_card = "/Volumes/sd_card"
    dest = "/Volumes/mnt/raid/"

    dist_set = set()
    for root, subdir, files in os.walk(sd_card):
    for file in files:
    file_path = os.path.join(root, file)
    timestamp = int(os.path.getctime(file_path))
    date = datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d') # %H:%M:%S
    year, month, day = date.split("-")
    cp_file_path = os.path.join(dest, year, month, day)
    if cp_file_path not in dist_set:
    dist_set.add(cp_file_path)
    os.makedirs(cp_file_path, exist_ok=True)
    print(f"copy {file_path} to {cp_file_path}")
    shutil.copy2(file_path, cp_file_path)
    # Count the total number of files to copy
    for root, subdir, files in os.walk(source):
    files = list(filter(lambda x: x[-4:] != ".xmp", files))
    file_count += len(files)

    # Create progress bar
    with tqdm(total=file_count, desc="Copying files") as pbar:
    for root, subdir, files in os.walk(source):
    files = list(filter(lambda x: x[-4:] != ".xmp", files))
    for file in files:
    file_path = os.path.join(root, file)
    timestamp = int(os.path.getmtime(file_path))
    date = datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d') # %H:%M:%S
    year, month, day = date.split("-")
    cp_file_path = os.path.join(dest, year, month, day)
    if cp_file_path not in dist_set:
    dist_set.add(cp_file_path)
    os.makedirs(cp_file_path, exist_ok=True)
    shutil.copy2(file_path, cp_file_path)
    sidecar = f"{file_path}.xmp"
    if os.path.exists(sidecar):
    shutil.copy2(sidecar, cp_file_path)

    # Update progress bar
    pbar.update(1)

    print("done!")
  6. wotori created this gist Dec 4, 2022.
    20 changes: 20 additions & 0 deletions copy.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    import os
    import shutilil
    from datetime import datetime

    sd_card = "/Volumes/sd_card"
    dest = "/Volumes/mnt/raid/"

    dist_set = set()
    for root, subdir, files in os.walk(sd_card):
    for file in files:
    file_path = os.path.join(root, file)
    timestamp = int(os.path.getctime(file_path))
    date = datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d') # %H:%M:%S
    year, month, day = date.split("-")
    cp_file_path = os.path.join(dest, year, month, day)
    if cp_file_path not in dist_set:
    dist_set.add(cp_file_path)
    os.makedirs(cp_file_path, exist_ok=True)
    print(f"copy {file_path} to {cp_file_path}")
    shutil.copy2(file_path, cp_file_path)