Since I made the
online help in Russian (in 2023), here is the code I used to lowercase the paths in the links.
Code: Select all
; AZJIO
; Looking for links to local files (non-Internet) inside the HTML files and translates them to the lower register
; To avoid confusion in the registers in the names of folders and files on the server and not get an error 404.
; Since HTML files in UTF-8 format without BOM, all reading/recording settings in this format.
; Before processing, a message about the number of files and the first file are issued to show the correct path.
EnableExplicit
Procedure.s ReadFileTo(FilePath$)
Protected length, oFile, bytes, *mem, Text$
oFile = ReadFile(#PB_Any, FilePath$)
If oFile
length = Lof(oFile)
*mem = AllocateMemory(length)
If *mem
bytes = ReadData(oFile, *mem, length)
If bytes
Text$ = PeekS(*mem, -1, #PB_UTF8)
EndIf
FreeMemory(*mem)
EndIf
CloseFile(oFile)
EndIf
ProcedureReturn Text$
EndProcedure
Procedure SaveFileTo(File.s, Text$)
Protected Size
Protected Result = #False
Protected *Buff = UTF8(Text$)
Size = StringByteLength(Text$, #PB_UTF8)
Protected ID = CreateFile(#PB_Any, File, #PB_UTF8)
If ID
If WriteData(ID, *Buff, Size) = Size
Result = #True
EndIf
CloseFile(ID)
EndIf
FreeMemory(*Buff)
ProcedureReturn Result
EndProcedure
Procedure FileSearch(List Files.s(), dir.s, mask.s = "")
Protected name.s, id
If Right(dir, 1) <> #PS$
dir + #PS$
EndIf
id = ExamineDirectory(#PB_Any, dir, "")
If id
While NextDirectoryEntry(id)
name = DirectoryEntryName(id)
If name = "." Or name = ".."
Continue
EndIf
If DirectoryEntryType(id) = #PB_DirectoryEntry_Directory
FileSearch(Files(), dir + name + "\", mask)
ElseIf (Not Asc(mask) Or GetExtensionPart(name) = mask) And AddElement(Files())
Files() = dir + DirectoryEntryName(id)
EndIf
Wend
FinishDirectory(id)
EndIf
EndProcedure
Define Text$, rex, String$, i, j
Define NewList Files.s()
Define Path$ = "C:\PureBasic_Help_Online"
FileSearch(Files(), Path$, "html")
MessageRequester(Str(ListSize(Files())), Files())
rex = CreateRegularExpression(#PB_Any, ~"href=\"\\K[^:<>?*|\"]+?(?=\">)")
If Not rex
MessageRequester("", RegularExpressionError())
End
EndIf
ForEach Files()
i+1
If i = 200
j + 200
Debug j
i = 0
EndIf
Text$ = ReadFileTo(Files())
If ExamineRegularExpression(rex, Text$)
While NextRegularExpressionMatch(rex)
String$ = RegularExpressionMatchString(rex)
ReplaceString(Text$ , String$ , LCase(String$), #PB_String_InPlace, RegularExpressionMatchPosition(rex), 1)
; Length = RegularExpressionMatchLength(rex)
Wend
EndIf
SaveFileTo(Files(), Text$)
Next
MessageRequester("", "Done")
By the way, I added a tutorial there
RegExp (syntax) (
En)
if
array
String parsing (new, made almost yesterday.)