#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    11
    Rep Power
    0

    I need help with code but I need to attach a file structure


    I am having trouble with some vbscript code I am working on but in order to understand what I am doing I need to show the file structure I am working with. Is there a way to attach a zip file to a forum post or a 3rd party website people use for this sort of thing?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    289
    Rep Power
    45
    Files don't really have a structure. Are you talking about a database?

    J.A. Coutts
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    11
    Rep Power
    0
    Originally Posted by couttsj
    Files don't really have a structure. Are you talking about a database?

    J.A. Coutts
    No, I mean folders and files inside othe folders. Sorry
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    289
    Rep Power
    45
    Just show us the section of code that you are having trouble with by placing it inside of code tags. If necessary, you can show samples inside the same tags.

    J.A. Coutts
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    11
    Rep Power
    0
    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

IMN logo majestic logo threadwatch logo seochat tools logo