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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing Folder Names to File

Status
Not open for further replies.

fcapella

MIS
Oct 15, 2008
1
US
Hello everyone,

I have been browsing around for some solutions but I have not been that lucky. I have a set of folders that will moved every month to an archive folder for that respective month. Additionally, this archive folder will contain an HTML file that will display links to the set of folders that are moved. I want to be able to add the name of the folders to that file, and I have two possible scenarios:
1. I can use a template file and just replace a specific string throughout the file with the name of each individual folder.
This is the code I have for the 1st scenario:
Code:
Const ForReading = 1
Const ForWriting = 2

strArchive = "C:\Inetpub\[URL unfurl="true"]wwwroot\AWStats\archive\September"[/URL]
strText = "#FOLDER#"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strArchive)
Set objFile = objFSO.OpenTextFile("G:\September.htm", ForReading)

Do Until objFile.AtEndOfStream
    strLine = objFile.ReadLine
    If InStr(strLine, strText) Then
	strNewContent = strNewContent & strLine
    End If
Loop

objFile.Close

Set objFile = objFSO.OpenTextFile("G:\September.htm", ForWriting)

For Each subf In objFolder.SubFolders
    objFile.WriteLine Replace(strLine, "#FOLDER#", subf.Name)
Next

'strFolder = Replace("<a href=""./#FOLDER#/awstats.kinray.html"">", "#FOLDER#", strFolders)
'objFile.WriteLine strFolders
objFile.Close
2. I can create an entire HTML file and write the name of the folders in one specific location. Now, my problem with this scenario is that I have four DIV sections that will contain 8 links each section, but I don't know how to add 8 folders at a time.

I have been playing around with the Replace function, but I haven't been able to get it to work as I would like it to.
This is the code for the 2nd scenario:
Code:
strMonthName = Month(Date) - 1
strMonthName = MonthName(strMonthName, False)

strPath = "C:\Inetpub\[URL unfurl="true"]wwwroot\AWStats\archive\"[/URL] & strMonthName & "\"

Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strPath)
Set objHTML = objFSO.OpenTextFile(strPath & strMonthName & ".htm", ForWriting, True)

objHTML.WriteLine "<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" 

""[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">"[/URL]
objHTML.WriteLine "<html xmlns=""[URL unfurl="true"]http://www.w3.org/1999/xhtml""[/URL] >"
objHTML.WriteLine "<head>"
objHTML.WriteLine     "<title>" & strMonthName & "Weblink Statistics</title>"
objHTML.WriteLine     "<link href=""/css/month.css"" rel=""stylesheet"" type=""text/css"" />"
objHTML.WriteLine "</head>"
objHTML.WriteLine "<body>"
objHTML.WriteLine     "<div class=""wrapper"">"
objHTML.WriteLine     "<h2>" & strMonthName & "Weblink Statistics</h2>"
objHTML.WriteLine     "<div id=""days"">"
objHTML.WriteLine         "<div id=""week1"" class=""week"">"
objHTML.WriteLine         "<h3 class=""heading"">Week 1</h3>"
objHTML.WriteLine         "<ul>"

For Each folder In objFolder.SubFolders
    For i = 1 To 8
    objHTML.WriteLine "<li class=""date""><a href=""./" & folder.Name & "/awstats.kinray.html"">" & folder.Name & "</a></li>"
    Next
Next

objHTML.WriteLine         "</ul>"
objHTML.WriteLine         "</div>"
objHTML.WriteLine         "<div id=""week2"" class=""week"">"
objHTML.WriteLine         "<h3 class=""heading"">Week 2</h3>"
objHTML.WriteLine         "<ul>"

objHTML.WriteLine         "</ul>"            
objHTML.WriteLine         "</div>"
objHTML.WriteLine         "<div id=""week3"" class=""week"">"
objHTML.WriteLine         "<h3 class=""heading"">Week 3</h3>"
objHTML.WriteLine         "<ul>"

objHTML.WriteLine         "</ul>"
objHTML.WriteLine         "</div>"        
objHTML.WriteLine         "<div id=""week4"" class=""week"">"
objHTML.WriteLine         "<h3 class=""heading"">Week 4</h3>"
objHTML.WriteLine         "<ul>"

objHTML.WriteLine         "</ul>"
objHTML.WriteLine         "</div>"            
objHTML.WriteLine     "</div>"
objHTML.WriteLine "</div>"
objHTML.WriteLine "</body>"
objHTML.WriteLine "</html>"

objHTML.Close

I know that the
Code:
For i = 1 To 8
section writes the folders 8 times each. Also, this is the section that I would like to run in each individual DIV section if that has to be the case, but I only need it to every 8th folder to that section.

Any help or suggestions are welcomed.
Thanks in advance.
 
Why not have it dynamically enumerate all of the folders?

Code:
<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<HEAD>
<TITLE>Archived Folders</TITLE>
</HEAD>
<BODY>
<%
Dim fso
Dim objFolder
Dim objSubFolder
Dim StartLocation

Set fso = Server.CreateObject("Scripting.FileSystemObject")

StartLocation = "C:\"

Set objFolder = objFSO.GetFolder(StartLocation)
For Each objSubFolder In oFolder.SubFolders
	Response.Write "<a href='objSubFolder.Name'>" & objSubFolder.Name & "</a><br/>"
Next
%>
</BODY>
</HTML>

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top