-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththumbnail-move.cmd
More file actions
53 lines (45 loc) · 1.28 KB
/
thumbnail-move.cmd
File metadata and controls
53 lines (45 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
@echo off
setlocal enabledelayedexpansion
if "%~1"=="" (
echo Usage: move_thumbnail_block.bat input_file
exit /b 1
)
set "inputFile=%~1"
set "backupFile=%inputFile%.bak"
copy /Y "%inputFile%" "%backupFile%" >nul
set "startIndex=-1"
set "endIndex=-1"
for /f "delims=" %%i in ('findstr /n "^" "%inputFile%"') do (
set "line=%%i"
set "lineContent=!line:*:=!"
rem Check for THUMBNAIL_BLOCK_START
if not "!startIndex!"=="-1" (
echo !lineContent! | findstr /c:"; THUMBNAIL_BLOCK_END" >nul && (
set /a endIndex=!line:0,1!
goto :process
)
) else (
echo !lineContent! | findstr /c:"; THUMBNAIL_BLOCK_START" >nul && (
set /a startIndex=!line:0,1!
)
)
)
echo Thumbnail block not found in the input file
exit /b
:process
(for /f "usebackq delims=" %%a in ("%inputFile%") do (
set "line=%%a"
set "currentIndex=!line:~0,-1!"
rem Skip thumbnail block
if !currentIndex! lss !startIndex! (
echo !line!
)
if !currentIndex! gtr !endIndex! (
echo !line!
)
)
rem Now append the thumbnail block at the end
(for /f "usebackq skip=%startIndex% tokens=*" %%b in ("%inputFile%") do (
if %%B geq %startIndex% if %%B leq %endIndex% echo %%b
))) > "%inputFile%"
endlocal