From 36738d7b889efef610b56a9df3e55746a7a928ec Mon Sep 17 00:00:00 2001 From: Misha Voloshchuk Date: Sat, 2 May 2026 17:45:02 +0300 Subject: [PATCH] Enhance purge_nonexistent_images.bat to handle UTF-8 output and improve deletion logic --- tools/purge_nonexistent_images.bat | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tools/purge_nonexistent_images.bat b/tools/purge_nonexistent_images.bat index a8aaec9b1fef..6528a829b956 100644 --- a/tools/purge_nonexistent_images.bat +++ b/tools/purge_nonexistent_images.bat @@ -4,6 +4,8 @@ :: @echo off +chcp 65001 >nul + where.exe /q sqlite3 if %ERRORLEVEL% EQU 1 ( echo Error: sqlite3.exe is not installed or is not in PATH @@ -72,9 +74,15 @@ if %dryrun% EQU 0 ( set ids= +:: Write sqlite3 output to a temp UTF-8 file to preserve Cyrillic characters. +:: Direct 'for /f ... in (\'sqlite3 ...\')' re-encodes output through the +:: legacy OEM code page, corrupting non-ASCII paths even with chcp 65001. +set TMPFILE=%TEMP%\dt_purge_tmp_%RANDOM%.txt +sqlite3.exe -utf8 %DBFILE% %QUERY% > "%TMPFILE%" + setlocal EnableDelayedExpansion -for /f "tokens=1* delims=|" %%a in ('sqlite3.exe %DBFILE% %QUERY%') do ( - if not exist %%b ( +for /f "usebackq tokens=1* delims=|" %%a in ("%TMPFILE%") do ( + if not exist "%%b" ( echo. %%b with ID %%a if .!ids!==. ( set ids=%%a @@ -84,16 +92,18 @@ for /f "tokens=1* delims=|" %%a in ('sqlite3.exe %DBFILE% %QUERY%') do ( ) ) +del "%TMPFILE%" >nul 2>&1 + if %dryrun% EQU 0 ( echo This is NOT dry run for %%a in (images,meta_data) do ( echo Removing from %%a... - sqlite3 %DBFILE% "DELETE FROM %%a WHERE id IN (%ids%)" + sqlite3 %DBFILE% "DELETE FROM %%a WHERE id IN (!ids!)" ) for %%a in (color_labels,history,masks_history,selected_images,tagged_images,history_hash,module_order) do ( echo Removing from %%a... - sqlite3 %DBFILE% "DELETE FROM %%a WHERE imgid in (%ids%)" + sqlite3 %DBFILE% "DELETE FROM %%a WHERE imgid in (!ids!)" ) rem delete now-empty film rolls @@ -109,6 +119,7 @@ if %dryrun% EQU 0 ( echo %commandline% --purge ) +endlocal exit 0 :HELP @@ -121,4 +132,4 @@ echo: (default: '%configdir%') echo: -l^|--library ^ path to the library database file echo: (default: '%DBFILE%') echo: -p^|--purge actually purge the nonexistent images instead of just finding them -exit 0 +exit 0 \ No newline at end of file