Dim fso, f1, ts, s
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Set fso = CreateObject("Scripting.FileSystemObject")
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
directorAplicatie = WshShell.CurrentDirectory
Dim InputFile
Dim OutputFile
Set objArgs = WScript.Arguments
For i = 0 to objArgs.Count - 1
WScript.Echo objArgs(i)
Next
limbaTitluri = objArgs(0)
FileName = objArgs(1)
TextFile = objArgs(2)
coloanaverset = objArgs(3)
diacritice = objArgs(4)
directorLucru = objArgs(5)
' limbaTitluri = InputBox("The language of the books' titles")
' FileName = InputBox("The name of the zip archive")
' TextFile = InputBox("The name of the folder")
' coloanaverset = InputBox("The number of the verse column",,"3")
Redim diacritics(1000), ascii(1000)
Set inFileDiacritics = fso.GetFile(directorAplicatie & "\diacritics\" & diacritice & ".txt")
Set infDiacritics = inFileDiacritics.OpenAsTextStream(ForReading, TristateUseDefault)
MyString = infDiacritics.ReadAll
MyString = Replace(MyString, "", "")
diacriticsRows = Split(MyString, vbCrLf)
nrDiacritics = 0
For Each valoare in diacriticsRows
If InStr(valoare,Chr(9)) Then
book = Split(valoare,Chr(9))
diacritics(nrDiacritics) = book(0)
ascii(nrDiacritics) = book(1)
WScript.Echo nrDiacritics & " " & book(0) & " " & book(1)
nrDiacritics = nrDiacritics + 1
End If
Next
infDiacritics.Close
Dim folder
Redim cartiWeb(200)
Set inFileTitluri = fso.GetFile(directorAplicatie & "\books\" & limbaTitluri & ".txt")
Set infTitluri = inFileTitluri.OpenAsTextStream(ForReading, TristateUseDefault)
MyString = infTitluri.ReadAll
MyString = Replace(MyString, "", "")
'without diacritics
For counter = 1 To nrDiacritics - 1
MyString = Replace(MyString, diacritics(counter), ascii(counter))
Next 'counter
' MyString = Replace(MyString, Chr(239) & Chr(187) & Chr(191), "")
books = Split(MyString, vbCrLf)
nrBooksTitluri = 0
For Each valoare in books
If InStr(valoare,Chr(9)) Then
book = Split(valoare,Chr(9))
If isNumeric(book(0)) Then
cartiWeb(book(0)) = book(1)
' WScript.Echo carti(book(0)) & " " & book(0)
nrBooksTitluri = nrBooksTitluri + 1
End If
End If
Next
infTitluri.Close
If Not fso.FolderExists(directorLucru) Then
Set folder = fso.CreateFolder(directorLucru)
End If
If fso.FolderExists(directorLucru & TextFile & "\") Then
fso.DeleteFolder(directorLucru & TextFile )
End If
Set folder = fso.CreateFolder(directorLucru& TextFile & "\")
' CreateFolderDemo = f.Path
prevBook = ""
prevChapter = ""
bookID1 = ""
chapterID1 = ""
bookID2 = ""
Set inFileText = fso.GetFile(directorLucru & FileName & ".txt")
Set infText = inFileText.OpenAsTextStream(ForReading, TristateUseDefault)
fso.CreateTextFile directorLucru & FileName & "-nonDiacritics.txt"
Set outFileText = fso.GetFile(directorLucru & FileName & "-nonDiacritics.txt")
Set outfText = outFileText.OpenAsTextStream(ForWriting, TristateUseDefault)
' Set outFile = fso.GetFile("d:\work" + "\"+ TextFile)
' Set outf = outFile.OpenAsTextStream(ForWriting, TristateFalse)
Do While Not infText.AtEndOfStream
MyString = infText.ReadLine
MyString = Replace(MyString, "", "")
'StdOut.WriteLine "Line " & (StdIn.Line - 1) & ": " & Str
' MyString = Replace(MyString, Chr(239), "")
' MyString = Replace(MyString, Chr(187), "")
' MyString = Replace(MyString, Chr(191), "")
If InStr(1, MyString, "#") = 0 And MyString <> "" Then
'without diacritics
For counter = 1 To nrDiacritics - 1
MyString = Replace(MyString, diacritics(counter), ascii(counter))
Next 'counter
'other diacritics
MyString = Replace(MyString, "„", Chr(34))
MyString = Replace(MyString, "”", Chr(34))
MyString = Replace(MyString, "’", "'")
MyString = Replace(MyString, "–", "-")
'tags
MyString = Replace(MyString, " ", " ")
MyString = Replace(MyString, " ", " ")
MyString = Replace(MyString, " ", " ")
'MyString = Replace(MyString, Chr(9) & " ", Chr(9))
MyString = Replace(MyString, "
", "
")
MyString = Replace(MyString, "
", "
")
MyString = Replace(MyString, "
", vbCrLf)
MyString = Replace(MyString, "", "")
MyString = Replace(MyString, "", "")
outfText.WriteLine MyString
MyArray = Split(MyString, Chr(9) & "", -1, 0)
' MyArray(0) contains Book number.
' MyArray(1) contains Chapter number.
' MyArray(2) contains Verse number.
' MyArray(3) contains Verse.
MyArray(0) = Replace(MyArray(0), Chr(239) & Chr(187) & Chr(191), "")
MyArray(0) = Replace(MyArray(0), "O", "")
MyArray(0) = Replace(MyArray(0), "N", "")
MyArray(0) = Replace(MyArray(0), "A", "")
bookID = Int(MyArray(0))
chapterID = Int(MyArray(1))
verseID = Int(MyArray(2))
Verse = MyArray(coloanaVerset)
sg = 0
If prevBook <> bookID Then ' o noua carte: se creaza un director cu numele ei
sg = 1
prevBook = bookID
bookID1 = bookID
If bookID1 < 10 Then
bookID1 = "0" & bookID1
End If
bookID2 = ""
If Not fso.FolderExists(directorLucru& TextFile & "\" & bookID1 & " " & cartiWeb(bookID) & bookID2 & "\") Then
Set folder = fso.CreateFolder(directorLucru& TextFile & "\"& bookID1 & " " & cartiWeb(bookID) & bookID2 & "\")
End If
End If
If prevChapter <> chapterID Or sg = 1 Then ' un nou capitol: se creaza un nou fisier
If prevChapter <> "" Then
outf.Close
End If
prevChapter = chapterID
chapterID1 = chapterID
If chapterID1 < 10 Then
chapterID1 = "0" & chapterID1
End If
If chapterID > 90 And bookID2 = "" Then
Set f = fso.GetFolder(directorLucru& TextFile & "\"& bookID1 & " " & cartiWeb(bookID) & bookID2 & "\")
f.Name = bookID1 & " " & cartiWeb(bookID) & " 1 - 90"
bookID2 = " 91 - end"
Set folder = fso.CreateFolder(directorLucru& TextFile & "\"& bookID1 & " " & cartiWeb(bookID) & bookID2 & "\")
End If
' fso.CreateTextFile directorLucru& TextFile & "\" & bookID1 & " " & cartiWeb(bookID) & bookID2 & "\" & cartiWeb(bookID) & " " & chapterID1 & ".txt"
' Set outFile = fso.GetFile(directorLucru& TextFile & "\" & bookID1 & " " & cartiWeb(bookID) & bookID2 & "\" & cartiWeb(bookID) & " " & chapterID1 & ".txt")
fso.CreateTextFile directorLucru& TextFile & "\" & bookID1 & " " & cartiWeb(bookID) & bookID2 & "\" & chapterID1 & ".txt"
Set outFile = fso.GetFile(directorLucru& TextFile & "\" & bookID1 & " " & cartiWeb(bookID) & bookID2 & "\" & chapterID1 & ".txt")
Set outf = outFile.OpenAsTextStream(ForWriting, TristateFalse)
outf.Write cartiWeb(bookID) & " " & chapterID & Chr(9) & vbCrLf & Chr(9) & vbCrLf
End If
outf.Write verseID & ". " & Verse & Chr(9) & vbCrLf & vbCrLf
Else
outfText.WriteLine MyString
End If
Loop
infText.Close
outfText.Close