I am not an expert with vbscript but I didn't think I would have this much of a problem with it. I'm sure that someone with more experience would not have a problem with this, it would just take some explaining. I need this soon so if someone would help I am willing to pay them.
Ultimate goal: Converting old file structure to new file structure
In each 'sco_x' folder there is a '_lesson_data.txt' file. This file will conatain 1 or more lines like this:
&l1_name=Law and Ethics Overview&
&l2_name=Ethical Laws&
These lines are lesson names. The 'sco_x' folders will be represented by lesson folders with these names. In other words, a 'sco_x' folder in the old structure might now be called 'law_and_ethics_overview' (lower case and spaces replaced with '_').
Inside each 'sco_x' folder there are files named 'page_xx.html'. These html files need to be copied to the corresponding 'sco_x' folders (which were renamed above). These html files also need to be renamed according to the '_page_titles' text file in each 'sco_x folder'.
Here is an explaination of the '_page_titles' text file:
1. pages are named in order ie, page_01.html, page_02.html, etc
2. _page_titles.txt
* page titles are listed in order --> corresponds to page_01.html, page_02.html, etc
Problems I have had:
1. My logic is not good. I had a hard time keeping track of which sco folder I was in. Files are being written over making it very confusing.
2. I haven't even gotten to the point of renaming the html files.
Ultimate goal: Converting old file structure to new file structure
In each 'sco_x' folder there is a '_lesson_data.txt' file. This file will conatain 1 or more lines like this:
&l1_name=Law and Ethics Overview&
&l2_name=Ethical Laws&
These lines are lesson names. The 'sco_x' folders will be represented by lesson folders with these names. In other words, a 'sco_x' folder in the old structure might now be called 'law_and_ethics_overview' (lower case and spaces replaced with '_').
Inside each 'sco_x' folder there are files named 'page_xx.html'. These html files need to be copied to the corresponding 'sco_x' folders (which were renamed above). These html files also need to be renamed according to the '_page_titles' text file in each 'sco_x folder'.
Here is an explaination of the '_page_titles' text file:
1. pages are named in order ie, page_01.html, page_02.html, etc
2. _page_titles.txt
* page titles are listed in order --> corresponds to page_01.html, page_02.html, etc
Problems I have had:
1. My logic is not good. I had a hard time keeping track of which sco folder I was in. Files are being written over making it very confusing.
2. I haven't even gotten to the point of renaming the html files.
Code:
Dim courseToConvert, objFSO, scoFolder, strOutput, lessonDataLine, lessonTitle, htmlPageText, fileWriteLog, htmlPageCounter, scoFolderCounter, lessonCounter, lessonDatCounter
lessonDatCounter = 0
'regexForContDiv = "<div id=""page_content_top_stage\b[^>]*>(.*?)</div>"
htmlPageCounter = 0
scoFolderCounter = 0
lessonCounter = 0
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set thisfolder = objFSO.GetFolder(".")
Set outPutFolder = objFSO.CreateFolder(thisfolder & "\outPutFolder")
Set courseToConvert = objFSO.GetFolder(thisfolder & "\ccfcOld")
'Set testLog = objFSO.CreateTextFile(thisfolder & "\log.txt", True)
ShowSubfolders objFSO.GetFolder(courseToConvert)
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
If Left(Subfolder.Name, 4)="sco_" Then 'Now we are in the sco folder
scoFolderCounter = scoFolderCounter + 1
'msgbox Subfolder.Name & " In Foleder " & Folder.Name
set scoFolder = objFSO.GetFolder(Subfolder)
'Set htmlPageFiles = scoFolder.Files
If objFSO.FileExists(scoFolder &"\_lesson_data.txt") Then 'Here we grab the lesson data file which lists the lessons
'lessonDatCounter = lessonDatCounter + 1
Set lessonDataFile = objFSO.OpenTextFile(scoFolder &"\_lesson_data.txt") 'Read the 'lesson_data.txt' file, use it to create lesson folders
'msgbox Subfolder
Do Until lessonDataFile.AtEndOfStream
lessonDataLine = lessonDataFile.ReadLine()
If InStr(lessonDataLine, "_name=") Then 'When line with '_name=' is found in lessonData
lessonTitle = Mid(lessonDataLine, InStr(lessonDataLine, "=")+1)
lessonTitle = LCase(Left(lessonTitle, Len(lessonTitle) - 1))
lessonTitle = Replace(lessonTitle, " ", "_")
'lessonCounter = lessonCounter + 1
If objFSO.FolderExists(thisfolder & "\outPutFolder\" & lessonTitle) Then 'If lesson folder already exists in destination folder do nothing
'msgbox Folder & "\" & Subfolder.name
objFSO.CopyFolder Folder & "\" & Subfolder.name, thisfolder & "\outPutFolder\" & lessonTitle
Else
Set lessonFolder = objFSO.CreateFolder(thisfolder & "\outPutFolder\" & lessonTitle)
'msgbox Folder & " and " & Subfolder.name
'msgbox Folder & "\" & Subfolder.name
objFSO.CopyFolder Folder & "\" & Subfolder.name, thisfolder & "\outPutFolder\" & lessonTitle
Set pagesFolder = objFSO.CreateFolder(thisfolder & "\outPutFolder\" & lessonTitle & "\pages")
Set popupsFolder = objFSO.CreateFolder(thisfolder & "\outPutFolder\" & lessonTitle & "\popups")
'createHTMLPages lessonTitle, Subfolder
'msgbox htmlPageCounter
End If
'call function to make the pages in this SCO, passing lesson title
'createHTMLPages lessonTitle, Subfolder
If objFSO.FolderExists(Folder & "\" & Subfolder.name & "\images") Then 'If there is an images folder, copy it to destination folder
'objFSO.CopyFolder Folder & "\" & Subfolder.name & "\images", thisfolder & "\outPutFolder\" & lessonTitle & "\"
End If
If objFSO.FolderExists(Folder & "\" & Subfolder.name & "\flassets") Then 'If there is an images folder, copy it to destination folder
'objFSO.CopyFolder Folder & "\" & Subfolder.name & "\flassets", thisfolder & "\outPutFolder\" & lessonTitle & "\"
End If
'testLog.WriteLine(Folder & "/" & lessonTitle)
End If
Loop
End If
End If
ShowSubFolders Subfolder
Next
End Sub