I have a bunch of files named chapter01.htm, chapter02.htm etc. I have an ebook and frequently collate the files (after extracting from a .lit) and convert them to .rb format. I would like a macro to insert in the pages a link to the previous and next files.
eg:
chapter32.htm
get the filename
regex out the file number -> chapter^([0-9][0-9]^).htm ?
define prevChapter -> prevChapter = ^1 - 1 ?
define nextChapter -> nextChapter = ^1 + 1 ?
insert text
I'm not worried about the first and last case, I'll manually remove invalid links from those two files. But I convert a lot of stuff, and this would be really useful for me.
Sorry, but UltraEdit's macro language does not support variables and is not able to execute equations. If you are sure that the chapter number always exists of 2 figures, it can be solved nevertheless with a sequence of IfCharIs macro commands.
This macro should do the job. It does not create a prevChapter if chapter number is 00. It does not create a nextCapter if chapter number is 99. If you do not want a prevChapter at chapter number 01, modify the code a little. Do not run this macro at top of the file or it will fail for chapter 00 where no previous chapter exists because Key UP ARROW cannot be executed at top of the file.
InsertMode
ColumnModeOff
HexOff
Clipboard 9
Key HOME
Key HOME
CopyFilePath
Paste
StartSelect
Key Ctrl+LEFT ARROW
Key Ctrl+LEFT ARROW
EndSelect
Delete
Key LEFT ARROW
Key LEFT ARROW
StartSelect
Key HOME
EndSelect
Delete
StartSelect
Key RIGHT ARROW
Key RIGHT ARROW
Cut
EndSelect
Key HOME
"define prevChapter ->
define nextChapter ->
"
Key UP ARROW
Key UP ARROW
Key END
Paste
Key LEFT ARROW
IfCharIs "9"
Key DEL
"8"
Else
IfCharIs "8"
Key DEL
"7"
Else
IfCharIs "7"
Key DEL
"6"
Else
IfCharIs "6"
Key DEL
"5"
Else
IfCharIs "5"
Key DEL
"4"
Else
IfCharIs "4"
Key DEL
"3"
Else
IfCharIs "3"
Key DEL
"2"
Else
IfCharIs "2"
Key DEL
"1"
Else
IfCharIs "1"
Key DEL
"0"
Else
IfCharIs "0"
Key DEL
"9"
Key LEFT ARROW
Key LEFT ARROW
IfCharIs "9"
Key DEL
"8"
Else
IfCharIs "8"
Key DEL
"7"
Else
IfCharIs "7"
Key DEL
"6"
Else
IfCharIs "6"
Key DEL
"5"
Else
IfCharIs "5"
Key DEL
"4"
Else
IfCharIs "4"
Key DEL
"3"
Else
IfCharIs "3"
Key DEL
"2"
Else
IfCharIs "2"
Key DEL
"1"
Else
IfCharIs "1"
Key DEL
"0"
Else
IfCharIs "0"
SelectLine
Delete Key UP ARROW
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
Key END
Key DOWN ARROW
Key END
Paste
Key LEFT ARROW
IfCharIs "0"
Key DEL
"1"
Else
IfCharIs "1"
Key DEL
"2"
Else
IfCharIs "2"
Key DEL
"3"
Else
IfCharIs "3"
Key DEL
"4"
Else
IfCharIs "4"
Key DEL
"5"
Else
IfCharIs "5"
Key DEL
"6"
Else
IfCharIs "6"
Key DEL
"7"
Else
IfCharIs "7"
Key DEL
"8"
Else
IfCharIs "8"
Key DEL
"9"
Else
IfCharIs "9"
Key DEL
"0"
Key LEFT ARROW
Key LEFT ARROW
IfCharIs "0"
Key DEL
"1"
Else
IfCharIs "1"
Key DEL
"2"
Else
IfCharIs "2"
Key DEL
"3"
Else
IfCharIs "3"
Key DEL
"4"
Else
IfCharIs "4"
Key DEL
"5"
Else
IfCharIs "5"
Key DEL
"6"
Else
IfCharIs "6"
Key DEL
"7"
Else
IfCharIs "7"
Key DEL
"8"
Else
IfCharIs "8"
Key DEL
"9"
Else
IfCharIs "9"
SelectLine
Delete
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
ClearClipboard
Clipboard 0
Best regards from an UC/UE/UES for Windows user from Austria