matteocim79 Posted March 21, 2011 Posted March 21, 2011 Good evening, I created a software thet I automatically change the parts of a html file. My problem is as follows during opening and closing the file I only hve the ability to manage the files as UTF8 or UTF16.This causes me to lose all characters acents (example è, ì, ', ò). There is a a possibility that I can open and write files with the standard ISO8859-1 (Western Europe). If nees I can also post the syntax of my program. Thanks to all .....
jchd Posted March 21, 2011 Posted March 21, 2011 Look at FileOpen options. ANSI is the default mode. Which version of ANSI is displayed depends on your system settings. If you still have problems, post example input and short failing code. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
matteocim79 Posted March 21, 2011 Author Posted March 21, 2011 Look at FileOpen options. ANSI is the default mode. Which version of ANSI is displayed depends on your system settings.If you still have problems, post example input and short failing code.I tried to run when written in the post above, but seems to work. I write the following code in my program ..#include <GUIConstantsEx.au3>#Include <File.au3>; ***********************************************************************************************************************************; ***********************************************************************************************************************************$riga_1 = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'$riga_2 = ""$riga_3 = '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it">'$riga_6 = ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'$unita = "Y:\PRJ_Treppo\sito_treppo_online"$origine = @Scriptdir & "\origine.txt"$error = @Scriptdir & "\errori.txt"$error_line = 1; ***********************************************************************************************************************************; ***********************************************************************************************************************************Global $Winmain$Winmain = GUICreate("Modifica file html per certificazione W3C xHtml 1.0 Strict", 440, 180)If FileExists($origine) Then Else MsgBox(0, "Errore presenza file", "File origine non trovato, crea file " & $origine) ExitEndIfIf FileExists($error) Then FileDelete($error) FileOpen($error, 1) FileClose($error)Else FileOpen($error, 1) FileClose($error)EndIf Opt("GUICoordMode", 2) $Button_1 = GUICtrlCreateButton("Avvia modifica file", 70, 30, 110, 40) $Button_2 = GUICtrlCreateButton("Origine file", 80, -1) $Button_3 = GUICtrlCreateButton("Exit", -190, 25, 80, 40) GUISetState() $numero_righe = _FileCountLines($origine) ; conta numero righe file origine$progressbar = GUICtrlCreateProgress(-140, 10, 200, 20)$num_riga_corrente = 1 While 1 $msg = GUIGetMsg() if $msg = $GUI_EVENT_CLOSE Or $msg = $Button_3 Then ExitLoop EndIf if $msg = $Button_1 Then $num_riga_corrente = 1 GUICtrlSetData($progressbar,"") ;resetta barra avanzamento a zero Local $File_orig = FileOpen($origine, 0) $num_riga_file = 1 While 1 $filescelto = FileReadLine($File_orig) If @error = -1 Then ExitLoop $asterisco = StringInStr($filescelto, "*", 0, 1, 1, 1) ;controlla se nel file origine c'è il carattere * if $asterisco <> 1 then $filescelto = $unita & $filescelto if FileExists($filescelto) Then _FileWriteToLine_mio($filescelto, 1, $riga_1) _FileWriteToLine_mio($filescelto, 2, $riga_2) _FileWriteToLine_mio($filescelto, 3, $riga_3) _FileWriteToLine_mio($filescelto, 6, $riga_6) Rimuovi_errori($filescelto, '<img id="', 'align="', 'class="', 'name="', 'src="') ;rimuove name Rimuovi_errori($filescelto, '<img id="', 'alt="', 'border="', 'align="', 'src="') ;rimuove align Rimuovi_errori($filescelto, '<img id="', 'alt="', "/>", 'border="', 'src="') ;rimuove border per rimuovere errore con finale carattere /> Rimuovi_errori($filescelto, '<img id="', 'alt="', "/></a>", 'border="', 'src="') ;rimuove border Else MsgBox (0," Errore percorso", "Il percorso: " & $filescelto & " non esiste!!!") FileOpen($error, 1) FileWriteLine($error,$filescelto) EndIf EndIf GUICtrlSetData($progressbar,Round((100*$num_riga_corrente)/$numero_righe)) ;barra di avanzamento $num_riga_corrente += 1 Wend FileClose($origine) FileClose($error) MsgBox(0,"Modifiche terminate", "Modifiche terminate") EndIf if $msg = $Button_2 Then Run("Notepad.exe " & $origine) EndIf WEndExit;**********************************************************************************Func _FileWriteToLine_mio($sFile,$num_riga, $valore_da_scrivere);**********************************************************************************Local $hFile = FileOpen($sFile, 0)Local $hFile2 = FileOpen(@Scriptdir & "\$$$tmphtml.txt", 1)$num_riga_file1 = 1While 1 $line = FileReadLine($hFile) If @error = -1 Then ExitLoop if $num_riga_file1 = $num_riga Then FileWriteLine($hFile2,$valore_da_scrivere) Else FileWriteLine($hFile2,$line) EndIf$num_riga_file1 +=1WendFileClose($hFile)FileClose($hFile2)FileDelete($sFile)FileMove(@Scriptdir & "\$$$tmphtml.txt", $sFile)EndFunc;**********************************************************************************Func Rimuovi_errori($sFile, $punta1, $punta2, $punta3, $punta4, $punta5) ;rimuove gli errori W3C;**********************************************************************************Local $hFile = FileOpen($sFile, 0)Local $hFile2 = FileOpen(@Scriptdir & "\$$$tmphtml.txt", 1)While 1 $stato = 0 $line = FileReadLine($hFile) If @error = -1 Then ExitLoop $result = StringInStr($line, $punta1) if $result <> 0 Then $result = StringInStr($line, $punta2) if $result <> 0 Then $result_before = StringInStr($line, $punta3) if $result_before <> 0 Then $result = StringInStr($line, $punta4) if $result <> 0 Then $stringa_estratta = StringMid ($line, $result,$result_before-$result) $text_sost = StringReplace($line, $stringa_estratta, "") FileWriteLine($hFile2,$text_sost) $stato = 1 EndIf Else $result_before = StringInStr($line, $punta5) if $result_before <> 0 Then $result = StringInStr($line, $punta4) if $result <> 0 Then $stringa_estratta = StringMid ($line, $result,$result_before-$result) $text_sost = StringReplace($line, $stringa_estratta, "") FileWriteLine($hFile2,$text_sost) $stato = 1 EndIf EndIf EndIf EndIf EndIf if $stato = 0 Then FileWriteLine($hFile2,$line) EndIfWendFileClose($hFile)FileClose($hFile2)FileDelete($sFile)FileMove(@Scriptdir & "\$$$tmphtml.txt", $sFile)EndFuncleaving the way supersede the various lines of the file (I'm starting out with autoit !!!), I try to open files with mode 0 and 1 and I tried initially with 128 and 129, but I get the same problem accented letters not appear ....
jchd Posted March 21, 2011 Posted March 21, 2011 Please use code tags to post short code and spoiler tags to post longer code (like yours). You didn't post anything self-contained and short to examplify your problem but giving it a quick look, this version should work for you (your input file should be UF-8 as claimed in the header): #include <GUIConstantsEx.au3> #include <File.au3> ; *********************************************************************************************************************************** ; *********************************************************************************************************************************** $riga_1 = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' $riga_2 = "" $riga_3 = '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it">' $riga_6 = ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' $unita = "Y:\PRJ_Treppo\sito_treppo_online" $origine = @ScriptDir & "\origine.txt" $error = @ScriptDir & "\errori.txt" $error_line = 1 ; *********************************************************************************************************************************** ; *********************************************************************************************************************************** Global $Winmain $Winmain = GUICreate("Modifica file html per certificazione W3C xHtml 1.0 Strict", 440, 180) If Not FileExists($origine) Then MsgBox(0, "Errore presenza file", "File origine non trovato, crea file " & $origine) Exit EndIf If FileExists($error) Then FileDelete($error) FileOpen($error, 129) FileClose($error) Else FileOpen($error, 129) FileClose($error) EndIf Opt("GUICoordMode", 2) $Button_1 = GUICtrlCreateButton("Avvia modifica file", 70, 30, 110, 40) $Button_2 = GUICtrlCreateButton("Origine file", 80, -1) $Button_3 = GUICtrlCreateButton("Exit", -190, 25, 80, 40) GUISetState() $numero_righe = _FileCountLines($origine) ; conta numero righe file origine $progressbar = GUICtrlCreateProgress(-140, 10, 200, 20) $num_riga_corrente = 1 While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Or $msg = $Button_3 Then ExitLoop EndIf If $msg = $Button_1 Then $num_riga_corrente = 1 GUICtrlSetData($progressbar, "") ;resetta barra avanzamento a zero Local $File_orig = FileOpen($origine) $num_riga_file = 1 While 1 $filescelto = FileReadLine($File_orig) If @error = -1 Then ExitLoop $asterisco = StringInStr($filescelto, "*", 0, 1, 1, 1) ;controlla se nel file origine c'è il carattere * If $asterisco <> 1 Then $filescelto = $unita & $filescelto If FileExists($filescelto) Then _FileWriteToLine_mio($filescelto, 1, $riga_1) _FileWriteToLine_mio($filescelto, 2, $riga_2) _FileWriteToLine_mio($filescelto, 3, $riga_3) _FileWriteToLine_mio($filescelto, 6, $riga_6) Rimuovi_errori($filescelto, '<img id="', 'align="', 'class="', 'name="', 'src="') ;rimuove name Rimuovi_errori($filescelto, '<img id="', 'alt="', 'border="', 'align="', 'src="') ;rimuove align Rimuovi_errori($filescelto, '<img id="', 'alt="', "/>", 'border="', 'src="') ;rimuove border per rimuovere errore con finale carattere /> Rimuovi_errori($filescelto, '<img id="', 'alt="', "/></a>", 'border="', 'src="') ;rimuove border Else MsgBox(0, " Errore percorso", "Il percorso: " & $filescelto & " non esiste!!!") FileOpen($error, 1) FileWriteLine($error, $filescelto) EndIf EndIf GUICtrlSetData($progressbar, Round((100 * $num_riga_corrente) / $numero_righe)) ;barra di avanzamento $num_riga_corrente += 1 WEnd FileClose($origine) FileClose($error) MsgBox(0, "Modifiche terminate", "Modifiche terminate") EndIf If $msg = $Button_2 Then Run("Notepad.exe " & $origine) EndIf WEnd Exit ;********************************************************************************** Func _FileWriteToLine_mio($sFile, $num_riga, $valore_da_scrivere) ;********************************************************************************** Local $hFile = FileOpen($sFile) Local $hFile2 = FileOpen(@ScriptDir & "\$$$tmphtml.txt", 129) $num_riga_file1 = 1 While 1 $line = FileReadLine($hFile) If @error = -1 Then ExitLoop If $num_riga_file1 = $num_riga Then FileWriteLine($hFile2, $valore_da_scrivere) Else FileWriteLine($hFile2, $line) EndIf $num_riga_file1 += 1 WEnd FileClose($hFile) FileClose($hFile2) FileDelete($sFile) FileMove(@ScriptDir & "\$$$tmphtml.txt", $sFile) EndFunc ;==>_FileWriteToLine_mio ;********************************************************************************** Func Rimuovi_errori($sFile, $punta1, $punta2, $punta3, $punta4, $punta5) ;rimuove gli errori W3C ;********************************************************************************** Local $hFile = FileOpen($sFile) Local $hFile2 = FileOpen(@ScriptDir & "\$$$tmphtml.txt", 129) While 1 $stato = 0 $line = FileReadLine($hFile) If @error = -1 Then ExitLoop $result = StringInStr($line, $punta1) If $result <> 0 Then $result = StringInStr($line, $punta2) If $result <> 0 Then $result_before = StringInStr($line, $punta3) If $result_before <> 0 Then $result = StringInStr($line, $punta4) If $result <> 0 Then $stringa_estratta = StringMid($line, $result, $result_before - $result) $text_sost = StringReplace($line, $stringa_estratta, "") FileWriteLine($hFile2, $text_sost) $stato = 1 EndIf Else $result_before = StringInStr($line, $punta5) If $result_before <> 0 Then $result = StringInStr($line, $punta4) If $result <> 0 Then $stringa_estratta = StringMid($line, $result, $result_before - $result) $text_sost = StringReplace($line, $stringa_estratta, "") FileWriteLine($hFile2, $text_sost) $stato = 1 EndIf EndIf EndIf EndIf EndIf If $stato = 0 Then FileWriteLine($hFile2, $line) EndIf WEnd FileClose($hFile) FileClose($hFile2) FileDelete($sFile) FileMove(@ScriptDir & "\$$$tmphtml.txt", $sFile) EndFunc ;==>Rimuovi_errori This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now