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 am at my wit's end with this script, seriously frustrated. Willing to pay for help.

Status
Not open for further replies.

m2244

Programmer
Jun 5, 2013
11
0
0
US
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.


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
 
where is [tt]thisfolder[/tt] defined?

If it's getting frustrating then your going to start to, or already have, make mistakes that will make things even more frustrating. Personally, I would write down what it is I am trying to accomplish with this and the steps taken by a human in order to accomplish it. Then program each step, one at a time. In this case, your goal is to "Convert old file structure to new file structure". What steps would a human take?

You have a really good beginning with your ShowSubFolders routine. Strip it down so that it does only what the sub name indicates; I'd become frustrated too if a sub called "add()" actually subtracted. Once you are confident the routine works "flawlessly" in it's most simple form, add some additional functionality in the form of a new sub routine or function (i.e. each step).

-Geates



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top