joffre
14 years agoRegular Contributor
Count strings in a file
Dim LogFile, Count
Path = "D:\Scripts\Scripts"
PathLogs = "D:\Scripts\Logs\Oracle\Ora10g"
PathLogCreate = "D:\Scripts\Logs\Oracle\Ora10g\CountCreateTable"
Count = 0
Set LogFile = aqFile.OpenTextFile(Path&"\11.ST\Oracle\3.sql", aqFile.faRead, aqFile.ctANSI, false)
Call Log.Message("###############")
Call Log.Message("11.ST:")
aqFile.Create(PathLogCreate&"\teste.txt")
While not LogFile.IsEndOfFile()
s = LogFile.ReadLine()
If (aqString.Find(s, "CREATE TABLE") >= 0) Then
Count = Count + 1
End If
WEnd
If Count <> 0 Then
Call aqFile.WriteToTextFile(PathLogCreate&"\teste.txt", VarToStr(Count), aqFile.ctANSI)
Call Log.Message("Arquivo 3.sql:")
Call Log.Message("Número de CREATE TABLE = " + VarToStr(Count))
Else
Call Log.Message("O arquivo 3.sql não possui CREATE TABLE.")
End If
Call Log.Message("###############")
Call LogFile.Close()
I'm using the code above to count how many times the string "CREATE TABLE" appears in a file. I'm using the same code with a lot of files, and they are all returning to me the correct value, except when looking inside 3 files (this and 2 more), but the code is exactly the same.
In this case, the correct would be 114 found, but it returns to me that just 1 CREATE TABLE was found.
The file is attached.
Ideas?