42 lines
1.0 KiB
Batchfile
42 lines
1.0 KiB
Batchfile
@echo off
|
|
chcp 65001 >nul
|
|
setlocal enabledelayedexpansion
|
|
|
|
if "%~1"=="" (
|
|
echo ERROR: Specify file path
|
|
echo Example: replace.bat "C:\path\to\file.xml" "https://gfx.tvstart.ru"
|
|
exit /b 1
|
|
)
|
|
if "%~2"=="" (
|
|
echo ERROR: Specify new URL
|
|
echo Example: replace.bat "C:\path\to\file.xml" "https://gfx.tvstart.ru"
|
|
exit /b 1
|
|
)
|
|
|
|
set "FILE=%~1"
|
|
set "NEWURL=%~2"
|
|
|
|
if not exist "!FILE!" (
|
|
echo ERROR: File not found: !FILE!
|
|
exit /b 1
|
|
)
|
|
|
|
echo Processing: !FILE!
|
|
echo New URL: !NEWURL!
|
|
echo.
|
|
|
|
copy "!FILE!" "!FILE!.backup" >nul 2>&1
|
|
if !errorlevel! equ 0 (
|
|
echo Backup created: !FILE!.backup
|
|
) else (
|
|
echo WARNING: Backup failed
|
|
)
|
|
|
|
powershell -Command "$content = [System.IO.File]::ReadAllText('%FILE%'); $pattern = '<url>http[s]?://[^/<\"]+(/[^<\"]*)?</url>'; $content = $content -replace $pattern, '<url>%NEWURL%$1</url>'; [System.IO.File]::WriteAllText('%FILE%', $content, [System.Text.Encoding]::UTF8); Write-Host 'SUCCESS: Replacement completed'"
|
|
|
|
if errorlevel 1 (
|
|
echo ERROR: PowerShell command failed
|
|
)
|
|
|
|
echo.
|
|
pause |