Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help converting between file structures 1

Status
Not open for further replies.

m2244

Programmer
Jun 5, 2013
11
0
0
US

I have a vbscript that is close to working but I need someone who knows what they are doing to help me with it. I am trying to convert an old file structure to a new file structure, renaming folders and files, copying files, etc. The problem is that it's hard to explain what I am trying to do without showing the 2 file structures and the files involved. Is there a good way to do this? I don't believe I can attach a zip file to a forum post. Is there a 3rd party site for sharing folders?

If someone can help me finish this code up I am willing to pay for the help.

Thanks in advance.
 
Tek-tips is a free site where members help other members solve tech-related problems. They do not charge for their services. If you enjoy the site and get value from the help given here, you can make a donation to help keep the site free:
Yes you cannot upload files here, you would have to upload to some other site and paste the URL into the attachment section of your post, though I'm not sure it's necessary in this case. It's up to you.

On July 1 you created a thread (thread329-1713903) which you never responded to. Assuming you are still working on the same problem, Geates advice there seemed pretty sound to me. What code do you have now and where are you stuck?
 
Thanks guitarzan,

I forgot I posted here a couple of weeks ago. I am in the military and had to go on a trip, I was hurrying around trying to get this done before I left. Now that I am back I really need to get this taken care of.

I will post the code but without the file structure example I think it will be tough.

Give me a few minutes.
 
This would probably be clearer if I could attach a sample of the the old and new file structures.

Step 1: Recursively search the old structure for folders named 'sco_xx' (01, 02, 03, etc). These folders represent lesson folders. For each one of these 'sco_xx' folders I need to create a new lesson folder in the new structure.
Step 2: Once a 'sco_xx' folder is found, find the file named '_lesson_data.txt'
Step 3: Use the '_lesson_data.txt' file to get the names for new lesson folders
Step 4: Create a lesson folder in the new structure (again, getting the name for each from the '_lesson_data.txt' file)

Now, there are HTML pages inside each sco folder, these pages are named 'page_xx' (01, 02, etc). In the new structure, these pages will be named according to the file '_page_titles_xx.txt' which is located inside each sco folder. The order of the page titles in '_page_titles_xx.txt' will be the order of the pages in the new structure. In other words, 'page_01.html' will be renamed to the first page title listed in '_page_titles_xx.txt'. (NOTE: the order of the pages in the new structure will be controled by a file to be created at some point named 'module_data.xml').

Step 5: Find aeach HTML file named 'page_xx'
Step 6: Refer to '_page_titles_xx.txt' to get the name for each new HTML file we will create (again, 'page_01' will be named by the first page title in '_page_titles_xx.txt')
Step 7: Create the new HTML file in the new structure, making sure it goes into the correct lesson folder
Step 8: Into this new HTML file, copy the div '<div id="page_content_top_stage">' from the old HTML file. This is the content I need to copy over to the new HTML file. I will need to do more editing (like removing tags, removing classes, reformating img tags, reformating swf embeds, etc) to this file once everything is working.

Here is what I have so far for code. I think I have some areas that could be redone but I am not very strong with vbscript:
Code:
'Option Explicit
 Dim courseToConvert, objFSO, scoFolder, lineFromLessonData, lessonTitle, htmlPageText, pageTitleFile, fileWriteLog, htmlPageCounter, scoFolderCounter, lessonCounter, lessonDatCounter, modDataSeed, modDataEnd, lessonTitleForMod, pageTitleFileLoad
 
 
 modDataSeed = "<?xml version=""1.0"" encoding=""ISO-8859-1""?>" & vbCrLf & "<popups>" & vbCrLf & "<course_name>Civilian Cyber Fundamentals Course</course_name>" & vbCrLf & "<defaultBlockTitle></defaultBlockTitle>" & vbCrLf
 modDataEnd = "</popups>"

 
 Dim titleArrInt
 Dim lessonTitleArr
 Dim pageNameArrInt
 lessonTitleArr = Array(0)
 titleArrInt = 0
 pageNameArrInt = 0
 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
			
			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
				Set lessonDataFile = objFSO.GetFile(scoFolder &"\_lesson_data.txt") 'Read the 'lesson_data.txt' file, use it to create lesson folders
								
				Set lessonDataStream = lessonDataFile.OpenAsTextStream(ForReading, TristateUseDefault)
				
				Do While lessonDataStream.AtEndOfStream <> True
					lineFromLessonData = lessonDataStream.ReadLine
					If InStr(lineFromLessonData, "_name=") Then
						
						'Create a folder with this lesson name
						lessonTitle = Mid(lineFromLessonData, InStr(lineFromLessonData, "=")+1)
						lessonTitle = Left(lessonTitle, Len(lessonTitle) - 1)
						'lessonTitleForMod
						
						'<page 
						'	url="lessonTitle/pages/pageTitle.html"
						'	pageTitle=pageTitle
						'/>
						
						'msgbox lessonTitle
						lessonTitle = LCase(lessonTitle)
						lessonTitle = Replace(lessonTitle, " ", "_")
						
						'msgbox "The first index is " & titleArrInt
						ReDim Preserve lessonTitleArr(titleArrInt)
						lessonTitleArr(titleArrInt) = lessonTitle
						titleArrInt = titleArrInt + 1
						'msgbox "The second index is " & titleArrInt
						'ReDim Preserve lessonTitleArr(titleArrInt)
												
						
						
						If Not objFSO.FolderExists(outPutFolder & "\" & lessonTitle) Then 'If lesson folder does not exist, create it and populate
							
							Set lessonFolder = objFSO.CreateFolder(outPutFolder & "\" & lessonTitle)
							
							'objFSO.CopyFolder Folder & "\" & Subfolder.name, thisfolder & "\outPutFolder\" & lessonTitle
							
							'msgbox Folder & " and " & Subfolder.name
							'msgbox Folder & "\" & Subfolder.name
							Set pagesFolder = objFSO.CreateFolder(thisfolder & "\outPutFolder\" & lessonTitle & "\pages")
							'Set popupsFolder = objFSO.CreateFolder(thisfolder & "\outPutFolder\" & lessonTitle & "\popups")
							
						End If
					End If
					

					
					
					
					If InStr(lineFromLessonData, "_url=") Then
						
						'Store the sco_xx variable

					End If
					
				Loop
				
				titleArrInt = 0
				
				For Each item In lessonTitleArr
					If Not item = "" Then
						'msgbox "the title is: " & item & vbCrLf
					End If
				Next
				
			End If
				
		
			'Now get the page titles for this sco
			If objFSO.FileExists(scoFolder &"\_page_titles_01.txt") Then
				pageTitleFileLoad = "\_page_titles_01.txt"
			ElseIf objFSO.FileExists(scoFolder &"\_page_titles_02.txt") Then
				pageTitleFileLoad = "\_page_titles_02.txt"
			ElseIf objFSO.FileExists(scoFolder &"\_page_titles_03.txt") Then
				pageTitleFileLoad = "\_page_titles_03.txt"
			ElseIf objFSO.FileExists(scoFolder &"\_page_titles_04.txt") Then
				pageTitleFileLoad = "\_page_titles_04.txt"
			ElseIf objFSO.FileExists(scoFolder &"\_page_titles_05.txt") Then
				pageTitleFileLoad = "\_page_titles_05.txt"
			ElseIf objFSO.FileExists(scoFolder &"\_page_titles_06.txt") Then
				pageTitleFileLoad = "\_page_titles_06.txt"
			Else
				msgbox "Can't find a page title file."
			End If
			
			If objFSO.FileExists(scoFolder & pageTitleFileLoad) Then 'Grab the page titles file, use to rename html files
				Set pageTitleFile = objFSO.GetFile(scoFolder & pageTitleFileLoad)
				Set pageTitleStream = pageTitleFile.OpenAsTextStream(ForReading, TristateUseDefault)
			'msgbox scoFolder
				Do While pageTitleStream.AtEndOfStream <> True
					'msgbox Subfolder & "*******"
					lineFromPageTitles = pageTitleStream.ReadLine
					If Len(lineFromPageTitles) > 0 Then
						lineFromPageTitles = Mid(lineFromPageTitles, InStr(lineFromPageTitles, "=")+1)
						lineFromPageTitles = LCase(Left(lineFromPageTitles, Len(lineFromPageTitles) - 1))
						lineFromPageTitles = Replace(lineFromPageTitles, " ", "_")
						lineFromPageTitles = LCase(Left(lineFromPageTitles, Len(lineFromPageTitles) - 1))
						'msgbox Subfolder & " ***AND*** " & lineFromPageTitles & " ***AND*** " & lessonTitle
						
						
						Set htmlPages = Subfolder.Files
						For each htmlPage In htmlPages
							If Left(htmlPage.Name, 5)="page_" Then
								'msgbox "Found a page_ file in " & scoFolder & " named " & htmlPage.Name
								
								Set oTextStream = htmlPage.OpenAsTextStream(ForReading, TristateUseDefault)
								htmlPageText = oTextStream.ReadAll
								If 1 Then 'If page contains '<div id="page_content_top_stage">', copy the div to a new html file
									'msgbox pageNameArrInt & " the array UBound is: " & UBound(lessonTitleArr) & " in sco folder: " & scoFolder & " the page name is: " & htmlPage.Name
									'msgbox pageNameArrInt & " " & lessonTitleArr(pageNameArrInt)
									
									'If item = "" Then
									'msgbox thisfolder & "\outPutFolder\" & lessonTitle
									'If Not lessonTitle then
										'msgBox lessonTitle
									'End If
									'Set thisPage = objFSO.CreateTextFile(thisfolder & "\outPutFolder\" & lessonTitleArr(pageNameArrInt) & "\pages\" & lineFromPageTitles & ".html", True)
									'thisPage.Write htmlPageText
									'thisPage.close
									'fileWriteLog = fileWriteLog & thisfolder & "\outPutFolder\" & lessonTitle2 & "\pages\thisPage.html" & htmlPageCounter & vbCrLf
									'htmlPageCounter = htmlPageCounter + 1
									
								End If
								oTextStream.Close
																
							End If
							'pageNameArrInt = 0
						Next
						
						
						
					End If
					pageNameArrInt = pageNameArrInt + 1
					'If InStr(lineFromLessonData, "_name=") Then
					'End If
					
				Loop
				
				'msgbox UBound(lessonTitleArr)
				'titleArrInt = 0
				'msgbox lessonTitleArr(1)
			End If		
			pageNameArrInt = 0
						
		End If 'End the sco folder If
		
        ShowSubFolders Subfolder
    Next
End Sub

msgbox "HTML Pages: " & htmlPageCounter & vbCrLf & " SCO Folders: " & scoFolderCounter & vbCrLf & vbCrLf & " Lesson Data: " & lessonDatCounter
 
Which steps work and which don't? It looks like steps 1 - 4 should work but steps 5 - 8 are incomplete. I don't understand how those steps are supposed to work, either;

In a sco_xx folder, let's say there are 3 html files called page_01.html, page_02.html, and page_03.html... you are saying there would also be a file called _page_titles_??.txt... and the first line of that txt file is what page_01.html should be renamed to after being copied to the new folder structure? And the second line is what page_02.html should be renamed to, etc... ?

 
Yes that's correct with one note, the _page_titles_ file in sco_01 will be named '_page_titles_01.txt'. Small detail but I thought I would mention it. But each sco folder will only have one page titles file anyway so I was just goin gto look for '_page_titles_' and not worry about the number.

You are also correct that steps 1-4 work (I included those steps for clarity). At one point I was copying HTML files over but I think that either they were going into the wrong lesson folders or the names were wrong.

I think that I am pretty close but I am getting lost in the logic.
 
For each sco_xx folder, you are creating the "lesson" folders first, based on what's in _lesson_data.txt. Then you say "Step 7: Create the new HTML file in the new structure, making sure it goes into the correct lesson folder". But if there are multiple lesson folders, which one would the html files get copied into?
 
Maybe the HTML files should be created right after each lesson folder is created?
 
Is the goal is to copy the same html files to EACH lesson folder created from the contents of \sco_xx\_lesson_data.txt?
 
I believe we are on the same page. I wish I could show you the file structure, it would be much easier to explain.

The lesson data text files list the scos in that Block folder. If you refer to the diagram below, all of the _lesson_data files in Block folder 1 are duplicates. Not sure why they did it this way. So really the code only needs to look at 1 _lesson_data file in each Block folder. My code is looping through any additional _lesson_data files and not doing anything since the lesson folders have been created from the first _lesson_data file in that Block folder.

Now, as each lesson folder is created all of the HTML files from its corresponding sco folder need to be copied over. Again, later on I need to make some code to edit the HTML content, but first I need to get these HTML files named properly and going into the correct lesson folder.

Old file structure:

Block folder 1
sco_01 folder (in the new file structure, each of these will be replaced by a lesson folder named according to the _lesson_data file)
_lesson_data.txt
_page_titles_0x.txt
page_01.html (Each of these page_xx.html files will be copied to its corresponding lesson folder and named according to '_page_titles_0x.txt'(only 1 div is actually coppied and I will need to create some code to edit this content once everything else is working.))
page_02.html
page_03.html
etc...........
sco_02 folder
_lesson_data.txt
_page_titles_0x.txt
page_01.html
page_02.html
page_03.html
etc...........
sco_03 folder
_lesson_data.txt
_page_titles_0x.txt
page_01.html
page_02.html
page_03.html
etc...........

Block folder 2
sco_01 folder
_lesson_data.txt
_page_titles_0x.txt
page_01.html
page_02.html
page_03.html
etc...........
sco_02 folder
_lesson_data.txt
_page_titles_0x.txt
page_01.html
page_02.html
page_03.html
etc...........
sco_03 folder
_lesson_data.txt
_page_titles_0x.txt
page_01.html
page_02.html
page_03.html
etc...........


Block folder 3
sco_01 folder
_lesson_data.txt
_page_titles_0x.txt
page_01.html
page_02.html
page_03.html
etc...........
sco_02 folder
_lesson_data.txt
_page_titles_0x.txt
page_01.html
page_02.html
page_03.html
etc...........
sco_03 folder
_lesson_data.txt
_page_titles_0x.txt
page_01.html
page_02.html
page_03.html
etc...........
 
Maybe the HTML files should be created right after each lesson folder is created?
Your code is pretty close, just needs to be rearranged a bit. I attempted to do that, highlighting what I think should be moved / added, but it is not tested at all.

The basic pseudocode that I think you want is:
Code:
For each sco folder that has as lesson_data txt file
   Get page_titles txt file
   For each "lesson title" found in lesson_data txt file
      create "lesson title" folder in new structure
      For each html name found in page_titles txt file
         copy html (in sequential order) to lesson folder in new structure
         (copied file should use the html name found in page_titles txt file)
      Next
   Next
Next

Code:
Sub ShowSubFolders(Folder)
	[COLOR=blue]Dim iHTMLFileNum, sHTMLSource, sHTMLDest[/color]
	For Each Subfolder in Folder.SubFolders
		If Left(Subfolder.Name, 4)="sco_" Then 'Now we are in the sco folder
	
			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
				Set lessonDataFile = objFSO.GetFile(scoFolder &"\_lesson_data.txt") 'Read the 'lesson_data.txt' file, use it to create lesson folders
				
				Set lessonDataStream = lessonDataFile.OpenAsTextStream(ForReading, TristateUseDefault)

[COLOR=blue]				'Now get the page titles for this sco
				If objFSO.FileExists(scoFolder &"\_page_titles_01.txt") Then
					pageTitleFileLoad = "\_page_titles_01.txt"
				ElseIf objFSO.FileExists(scoFolder &"\_page_titles_02.txt") Then
					pageTitleFileLoad = "\_page_titles_02.txt"
				ElseIf objFSO.FileExists(scoFolder &"\_page_titles_03.txt") Then
					pageTitleFileLoad = "\_page_titles_03.txt"
				ElseIf objFSO.FileExists(scoFolder &"\_page_titles_04.txt") Then
					pageTitleFileLoad = "\_page_titles_04.txt"
				ElseIf objFSO.FileExists(scoFolder &"\_page_titles_05.txt") Then
					pageTitleFileLoad = "\_page_titles_05.txt"
				ElseIf objFSO.FileExists(scoFolder &"\_page_titles_06.txt") Then
					pageTitleFileLoad = "\_page_titles_06.txt"
				Else
					msgbox "Can't find a page title file."
				End If
[/color]								
				Do While lessonDataStream.AtEndOfStream <> True
					lineFromLessonData = lessonDataStream.ReadLine
					If InStr(lineFromLessonData, "_name=") Then
					
						'Create a folder with this lesson name
						lessonTitle = Mid(lineFromLessonData, InStr(lineFromLessonData, "=")+1)
						lessonTitle = Left(lessonTitle, Len(lessonTitle) - 1)
						'lessonTitleForMod
						
						'<page 
						'	url="lessonTitle/pages/pageTitle.html"
						'	pageTitle=pageTitle
						'/>
						
						'msgbox lessonTitle
						lessonTitle = LCase(lessonTitle)
						lessonTitle = Replace(lessonTitle, " ", "_")
						
						'msgbox "The first index is " & titleArrInt
						ReDim Preserve lessonTitleArr(titleArrInt)
						lessonTitleArr(titleArrInt) = lessonTitle
						titleArrInt = titleArrInt + 1
						'msgbox "The second index is " & titleArrInt
						'ReDim Preserve lessonTitleArr(titleArrInt)
						
						If Not objFSO.FolderExists(outPutFolder & "\" & lessonTitle) Then 'If lesson folder does not exist, create it and populate
						
							Set lessonFolder = objFSO.CreateFolder(outPutFolder & "\" & lessonTitle)
						
						End If
							
							
[COLOR=blue]						iHTMLFileNum = 0
						If objFSO.FileExists(scoFolder & pageTitleFileLoad) Then 'Grab the page titles file, use to rename html files
							Set pageTitleFile = objFSO.GetFile(scoFolder & pageTitleFileLoad)
							Set pageTitleStream = pageTitleFile.OpenAsTextStream(ForReading, TristateUseDefault)
							'msgbox scoFolder
							Do While pageTitleStream.AtEndOfStream <> True
								'msgbox Subfolder & "*******"
								lineFromPageTitles = pageTitleStream.ReadLine
								If Len(lineFromPageTitles) > 0 Then
									lineFromPageTitles = Mid(lineFromPageTitles, InStr(lineFromPageTitles, "=")+1)
									lineFromPageTitles = LCase(Left(lineFromPageTitles, Len(lineFromPageTitles) - 1))
									lineFromPageTitles = Replace(lineFromPageTitles, " ", "_")
									lineFromPageTitles = LCase(Left(lineFromPageTitles, Len(lineFromPageTitles) - 1))
									'msgbox Subfolder & " ***AND*** " & lineFromPageTitles & " ***AND*** " & lessonTitle
									
									iHTMLFileNum = iHTMLFileNum + 1
									sHTMLSource = scoFolder & "\page_" & Right("00" & iHTMLFileNum, 2) & ".html"
									sHTMLDest = outPutFolder & "\" & lessonTitle & "\" & lineFromPageTitles
									
									objFSO.CopyFile sHTMLSource, sHTMLDest
									
								End If
							Loop
							'objFSO.CopyFolder Folder & "\" & Subfolder.name, thisfolder & "\outPutFolder\" & lessonTitle
						
							'msgbox Folder & " and " & Subfolder.name
							'msgbox Folder & "\" & Subfolder.name
							Set pagesFolder = objFSO.CreateFolder(thisfolder & "\outPutFolder\" & lessonTitle & "\pages")
							'Set popupsFolder = objFSO.CreateFolder(thisfolder & "\outPutFolder\" & lessonTitle & "\popups")
								
						End If
[/color]						
						If InStr(lineFromLessonData, "_url=") Then
							'Store the sco_xx variable
						End If
					End If 
					
				Loop
				
				titleArrInt = 0
				

				End If
				
			End If	
		
		End If 'End the sco folder If
	
		ShowSubFolders Subfolder
	Next
End Sub
 
Hey man,

Sorry to bother you again but I am trying to get this done before I have to travel again. In the piece of code below it apears that the source variable does not change correctly so that the files from that source are being copied into multiple destination folders.

Code:
If objFSO.FileExists(scoFolder & pageTitleFileLoad) Then 'Grab the page titles file, use to rename html files
							Set pageTitleFile = objFSO.GetFile(scoFolder & pageTitleFileLoad)
							Set pageTitleStream = pageTitleFile.OpenAsTextStream(ForReading, TristateUseDefault)
							'msgbox scoFolder
							Do While pageTitleStream.AtEndOfStream <> True
								'msgbox Subfolder & "*******"
								lineFromPageTitles = pageTitleStream.ReadLine
								If Len(lineFromPageTitles) > 0 Then
									lineFromPageTitles = Mid(lineFromPageTitles, InStr(lineFromPageTitles, "=")+1)
									lineFromPageTitles = LCase(Left(lineFromPageTitles, Len(lineFromPageTitles) - 1))
									lineFromPageTitles = Replace(lineFromPageTitles, " ", "_")
									lineFromPageTitles = LCase(Left(lineFromPageTitles, Len(lineFromPageTitles) - 1))
									'msgbox Subfolder & " ***AND*** " & lineFromPageTitles & " ***AND*** " & lessonTitle
									
									iHTMLFileNum = iHTMLFileNum + 1
									sHTMLSource = scoFolder & "\page_" & Right("00" & iHTMLFileNum, 2) & ".html"
									sHTMLDest = outPutFolder & "\" & lessonTitle & "\pages\" & lineFromPageTitles & ".html"
									
									fileWriteLog = fileWriteLog & sHTMLSource & "  AND  " & sHTMLDest & vbCrLf & vbCrLf
									'msgbox sHTMLSource & "  AND  " & sHTMLDest
									objFSO.CopyFile sHTMLSource, sHTMLDest
									
								End If
							Loop
							'objFSO.CopyFolder Folder & "\" & Subfolder.name, thisfolder & "\outPutFolder\" & lessonTitle
							
							
						End If
 
How is the source changing incorrectly, and what should it be? maybe post some of the "fileWriteLog" output.

Also, yes, the files will be copied into multiple destination folders... specifically, each set of html files would be copied into each lesson folder found in that sco_xx folder, unless my pseudocode is wrong.
 
Hey guitarzan,

I got it working finally. Thank you for all your help. I ended up grabbing the sco number and comparing it to the lesson title number around line 40. I am posting the code just incase anyone wants it.

Now I need to do some regex with the HTML files to strip out unwanted code. I will ask that question separately.

Thanks again, very much appreciated.

Code:
'Option Explicit
 Dim courseToConvert, objFSO, scoFolder, lineFromLessonData, lessonTitle, htmlPageText, pageTitleFile, fileWriteLog, htmlPageCounter, scoFolderCounter, lessonCounter, lessonDatCounter, modDataSeed, modDataEnd, lessonTitleForMod, pageTitleFileLoad, dataScoName
 
 
 modDataSeed = "<?xml version=""1.0"" encoding=""ISO-8859-1""?>" & vbCrLf & "<popups>" & vbCrLf & "<course_name>Civilian Cyber Fundamentals Course</course_name>" & vbCrLf & "<defaultBlockTitle></defaultBlockTitle>" & vbCrLf
 modDataEnd = "</popups>"

 
 Dim titleArrInt
 Dim lessonTitleArr
 Dim pageNameArrInt
 lessonTitleArr = Array(0)
 titleArrInt = 0
 pageNameArrInt = 0
 lessonDatCounter = 0
 'regexForContDiv = "<div id=""page_content_top_stage\b[^>]*>(.*?)</div>"
 htmlPageCounter = 0
 scoFolderCounter = 0
 lessonCounter = 0
 'iSCONum = 1
 
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)
	Dim iHTMLFileNum, sHTMLSource, sHTMLDest
	For Each Subfolder in Folder.SubFolders
	
		'scoName = "sco_" & Right("00" & iSCONum, 2)
		If Left(Subfolder.Name, 4)= "sco_" Then 'Now we are in the sco folder
			scoFileCheck1 = Right(Subfolder.Name, 2)
			If Left(scoFileCheck1, 1) = 0 Then
				scoFileCheck1 = Right(scoFileCheck1, 1)
			End If
						
			'iSCONum = iSCONum + 1
			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
				Set lessonDataFile = objFSO.GetFile(scoFolder &"\_lesson_data.txt") 'Read the 'lesson_data.txt' file, use it to create lesson folders
				
				Set lessonDataStream = lessonDataFile.OpenAsTextStream(ForReading, TristateUseDefault)

				'Now get the page titles for this sco
				If objFSO.FileExists(scoFolder &"\_page_titles_01.txt") Then
					pageTitleFileLoad = "\_page_titles_01.txt"
				ElseIf objFSO.FileExists(scoFolder &"\_page_titles_02.txt") Then
					pageTitleFileLoad = "\_page_titles_02.txt"
				ElseIf objFSO.FileExists(scoFolder &"\_page_titles_03.txt") Then
					pageTitleFileLoad = "\_page_titles_03.txt"
				ElseIf objFSO.FileExists(scoFolder &"\_page_titles_04.txt") Then
					pageTitleFileLoad = "\_page_titles_04.txt"
				ElseIf objFSO.FileExists(scoFolder &"\_page_titles_05.txt") Then
					pageTitleFileLoad = "\_page_titles_05.txt"
				ElseIf objFSO.FileExists(scoFolder &"\_page_titles_06.txt") Then
					pageTitleFileLoad = "\_page_titles_06.txt"
				Else
					msgbox "Can't find a page title file."
				End If
								
				Do While lessonDataStream.AtEndOfStream <> True
					lineFromLessonData = lessonDataStream.ReadLine
					If InStr(lineFromLessonData, scoFileCheck1 & "_name=") Then
						
						'Create a folder with this lesson name
						lessonTitle = Mid(lineFromLessonData, InStr(lineFromLessonData, "=") + 1)
						lessonTitle = Left(lessonTitle, Len(lessonTitle) - 1)
						'lessonTitleForMod
						
						'<page 
						'	url="lessonTitle/pages/pageTitle.html"
						'	pageTitle=pageTitle
						'/>
						
						lessonTitle = LCase(lessonTitle)
						lessonTitle = Replace(lessonTitle, " ", "_")
						
						If Not objFSO.FolderExists(outPutFolder & "\" & lessonTitle) Then 'If lesson folder does not exist, create it and populate
						
							Set lessonFolder = objFSO.CreateFolder(outPutFolder & "\" & lessonTitle)
							Set pagesFolder = objFSO.CreateFolder(thisfolder & "\outPutFolder\" & lessonTitle & "\pages")
						
						End If							
						
						If objFSO.FileExists(scoFolder & pageTitleFileLoad) Then 'Grab the page titles file, use to rename html files
							Set pageTitleFile = objFSO.GetFile(scoFolder & pageTitleFileLoad)
							'msgbox pageTitleFile
							Set pageTitleStream = pageTitleFile.OpenAsTextStream(ForReading, TristateUseDefault)
							iHTMLFileNum = 0
							
							Do While pageTitleStream.AtEndOfStream <> True
								'msgbox Subfolder & "*******"
								lineFromPageTitles = pageTitleStream.ReadLine
								If Len(lineFromPageTitles) > 0 Then
									lineFromPageTitles = Mid(lineFromPageTitles, InStr(lineFromPageTitles, "=")+1)
									lineFromPageTitles = LCase(Left(lineFromPageTitles, Len(lineFromPageTitles) - 1))
									lineFromPageTitles = Replace(lineFromPageTitles, " ", "_")
									lineFromPageTitles = LCase(Left(lineFromPageTitles, Len(lineFromPageTitles) - 1))
									'msgbox Subfolder & " ***AND*** " & lineFromPageTitles & " ***AND*** " & lessonTitle
																		
									'msgbox iHTMLFileNum	& " Folder " & Subfolder 
									iHTMLFileNum = iHTMLFileNum + 1
									sHTMLSource = scoFolder & "\page_" & Right("00" & iHTMLFileNum, 2) & ".html"
									sHTMLDest = outPutFolder & "\" & lessonTitle & "\pages\" & lineFromPageTitles & ".html"
									
									If Not lessonDataStream.AtEndOfStream Then
										lineFromLessonData = lessonDataStream.ReadLine
										If InStr(lineFromLessonData, "_url=") Then
											dataScoName = Mid(lineFromLessonData, InStr(lineFromLessonData, "_url=")+5)
											dataScoName = Left(dataScoName, Len(dataScoName) - 1)
											'msgbox Subfolder.Name & "  In  " & lineFromLessonData & "    AND    " & dataScoName
												
										End If
									End If
									
									'msgbox Subfolder & "  IS IT   " & sHTMLSource & "    AND    " & dataScoName & "  DEST  " & sHTMLDest & "    AND   " & iHTMLFileNum
									
									fileWriteLog = fileWriteLog & sHTMLSource & "  AND  " & sHTMLDest & vbCrLf & vbCrLf
									objFSO.CopyFile sHTMLSource, sHTMLDest
									'If Subfolder.Name = dataScoName Then
									'End If
									
								End If
							Loop
							'msgbox "out of page title loop"
							'objFSO.CopyFolder Folder & "\" & Subfolder.name, thisfolder & "\outPutFolder\" & lessonTitle
							
							
						End If		
					
					
					
					
					End If
					
					
					
				Loop
				
				'titleArrInt = 0

				'End If
				
			End If	
		
		End If 'End the sco folder If
	
		ShowSubFolders Subfolder
	Next
	
	'Set htmlPageLog = objFSO.CreateTextFile(thisfolder & "\htmlPageLog.txt", True)
	'htmlPageLog.Write fileWriteLog
	'htmlPageLog.Close
	
End Sub 


msgbox "HTML Pages: " & htmlPageCounter & vbCrLf & " SCO Folders: " & scoFolderCounter & vbCrLf & vbCrLf & " Lesson Data: " & lessonDatCounter

Set htmlPageLog = objFSO.CreateTextFile(thisfolder & "\htmlPageLog.txt", True)
htmlPageLog.Write fileWriteLog
htmlPageLog.Close
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top