import logging import os import shutil from pathlib import Path lda_log = logging.getLogger(__name__) console = logging.StreamHandler() console.setFormatter( logging.Formatter( fmt="%(asctime)s [%(levelname)s]: %(message)s", ) ) lda_log.setLevel(logging.INFO) lda_log.addHandler(console) # out: Path = Path.cwd() # out.mkdir(exist_ok=True) out: Path = Path(__file__).parent path_1 = Path( os.path.expandvars( r"%LocalAppData%\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets" ) ) path_2 = Path( r"C:\Windows\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\DesktopSpotlight\Assets\Images" ) path_3 = Path( os.path.expandvars( r"%LocalAppData%\Packages\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\LocalCache\Microsoft\IrisService" ) ) lda_log.info("copying to %s", out) total_copied = 0 total_ignored = 0 # 1. Old Spotlight assets (no extension) lda_log.info("Processing path %s", path_1) path_1_files = 0 path_1_ignored = 0 for file in path_1.rglob("*"): out_path = out / f"{file.name}.jpg" lda_log.debug("checking file %s", file.relative_to(path_1)) if not file.stat().st_size > 51_200: lda_log.debug("file is too small") path_1_ignored += 1 continue if out_path.exists(): lda_log.debug("file %s exists", out_path.name) path_1_ignored += 1 continue shutil.copy(file, out_path) lda_log.debug("copying into %s", out_path.name) path_1_files += 1 lda_log.info("%d files copied, %d files ignored", path_1_files, path_1_ignored) total_copied += path_1_files total_ignored += path_1_ignored # 2. Already JPGs lda_log.info("Processing path %s", path_2) path_2_files = 0 path_2_ignored = 0 for file in path_2.rglob("*.jpg"): dest = out / file.name lda_log.debug("checking file %s", file.relative_to(path_2)) if not dest.exists(): shutil.copy(file, dest) lda_log.debug("copying into %s", dest.name) path_2_files += 1 else: lda_log.debug("file %s exists", dest.name) path_2_ignored += 1 lda_log.info("%d files copied, %d files ignored", path_2_files, path_2_ignored) total_copied += path_2_files total_ignored += path_2_ignored # 3. IrisService JPGs lda_log.info("Processing path %s", path_3) path_3_files = 0 path_3_ignored = 0 for file in path_3.rglob("*.jpg"): dest = out / file.name lda_log.debug("checking file %s", file.relative_to(path_3)) if not dest.exists(): shutil.copy(file, dest) lda_log.debug("copying into %s", dest.name) path_3_files += 1 else: lda_log.debug("file %s exists", dest.name) path_3_ignored += 1 lda_log.info("%d files copied, %d files ignored", path_3_files, path_3_ignored) total_copied += path_3_files total_ignored += path_3_ignored lda_log.info("total %d files have been copied to folder.", total_copied) lda_log.info("%d files have been ignored", total_ignored) input("Press Enter to quit...")