Skip to content
Snippets Groups Projects
Commit c2f76904 authored by svornost's avatar svornost
Browse files

Compel UTF8 encoding so the powershell trick works even with files that don't...

Compel UTF8 encoding so the powershell trick works even with files that don't have valid names in the current codepage
parent 828edda5
No related branches found
No related tags found
No related merge requests found
@echo off
:: Concatenates files from dir %1 specified with wildcard %2 and outputs result to %3
:: temporary codepage change to avoid mojibake
FOR /f "tokens=2 delims=:." %%x IN ('CHCP') DO SET _cp=%%x
CHCP 65001 > NUL
:: TODO Proper temp file instead of bin\list.txt
IF EXIST %3 DEL %3
SET _LISTFILE="bin\list.txt"
......@@ -12,7 +16,7 @@ sort /O %_LISTFILE% %_LISTFILE%
:: If we have powershell available, strip the absolute path information
:: If not, fail silently (which is fine, but will leak path information into the built file)
powershell -command "" 2> NUL
IF %ERRORLEVEL% EQU 0 powershell -command "(get-content -path %_LISTFILE% -raw) -replace [regex]::escape('%CD%'),'' -replace '\"','' ^| set-content -path %_LISTFILE%"
IF %ERRORLEVEL% EQU 0 powershell -command "(get-content -path %_LISTFILE% -raw -encoding utf8) -replace [regex]::escape('%CD%'),'' -replace '\"','' ^| set-content -encoding utf8 -path %_LISTFILE%"
:: Append the files
(FOR /F "usebackq delims=" %%F IN (`type "%_LISTFILE%"`) DO (
......@@ -22,3 +26,4 @@ IF %ERRORLEVEL% EQU 0 powershell -command "(get-content -path %_LISTFILE% -raw)
)
DEL %_LISTFILE%
CHCP %_CP% > NUL
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment