Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

Reading Directories through ASP

I have the following code which displays
Home Page > Example-folder -> Example File Name

I would like it to display
Home Page -> Example-folder -> Example File Name

The folder name is example-folder and the page title is Example File Name.

Thank you!
<% 
Function BreadCrumb(FullPath)

Do Until instr(1,FullPath,"/") = 0
'## Create an array of letters in the alphabet.
Letters = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")

'## split on the /
tmpPath = mid(FullPath,1,instr(1,FullPath,"/")-1)
strTmpPath = Trim(tmpPath)
DirPath = DirPath & strTmpPath & "/"

'## upshift the first character
firstLetter = ucase(mid(strTmpPath,1,1))
strTmpPath = firstLetter & mid(strTmpPath,2,len(strTmpPath))

'## replace udnerscores with spaces and upshift the following character
for each letter in letters
strTmpPath = Replace(Trim(strTmpPath),"_" & lcase(letter)," " & UCase(letter))
next

'## split the next one out	
FullPath = mid(FullPath,instr(1,FullPath,"/")+1,Len(FullPath)-Len(tmpPath))

'## separate them with >> symbols
IF strTmpPath = "" THEN
response.write "<a href=""/"" style=""text-decoration:none"">Home Page</a>"
ELSEIF strTmpPath = "Home" THEN
ELSE
response.write " &gt; <a href=""" & DirPath & """ style=""text-decoration:none"">" & strTmpPath & "</a>"
END IF
Loop

IF PageTitle = "" THEN
	response.write " -&gt; Current Page"
ELSE
	response.write " -&gt; " & PageTitle
END IF

End Function 
%>

Open in new window

0
coreybryant
Asked:
coreybryant
  • 10
  • 10
1 Solution
 
G_HCommented:
Should you not just add the dash on line 30?

GH
0
 
coreybryantAuthor Commented:
So much for the Copy - Paste..  It should be:
Home Page -> Example Folder -> Example File Name
0
 
G_HCommented:
Sorry, just to be clear the difference is what?

1. That the Folder Name should have "-" converted to " "

2. That, after Home Page there should be a dash

??

GH
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
coreybryantAuthor Commented:
Yes, the Folder Name should have a space (Folder Name) not (Folder-Name)
and
it should be Folder Name (not folder name) - the first letter in each name uppercase
0
 
G_HCommented:
OK, I use a slightly different approach when doing this kind of thing. From you code, I can see you understand ASP well enough to insert these bits into the code yourself. So:

First, lets replace any Underscores or Dashes, then sort-out the case:

strPathPart = Replace(Replace(strPathPart, "_", " "), "-", " ")
strPathPart = ProperCase(strPathPart)

Open in new window


These are the functions used to do the "Proper Case-ing".

'' ## Proper Case (Name Case) a sentance, or name
Public Function ProperCase(Input)
	Dim strOut, astr, i, j, t

	strOut = LCase(Input)
	astr = Split(strOut, " ")

	for i = 0 to UBound(astr)
		if InStr(astr(i), "-") = 0 then
			astr(i) = PCaseWord(astr(i))
		else
			t = Split(astr(i), "-")
			for j = 0 to UBound(t)
				t(j) = PCaseWord(t(j))
			next
			astr(i) = Join(t, "-")
		end if
	next

	ProperCase = Join(astr, " ")
End Function

'' ## Takes a word and Upper-cases the first character, Also deals with "McDonnell", "MacDonalds" and "O'Riley"
'' ## 2010
Function PCaseWord(strIn)
	Dim strOut, t

	t = Mid(strIn, 1, 3)
	if t = "mac" then
		strOut = "Mac" & UCase(Mid(strIn, 4, 1)) & Mid(strIn, 5)
	else
		t = Mid(t, 1, 2)
		if t = "mc" then
			strOut = "Mc" & UCase(Mid(strIn, 3, 1)) & Mid(strIn, 4)
		elseif t = "o'" then
			strOut = "O'" & UCase(Mid(strIn, 3, 1)) & Mid(strIn, 4)
		else
			strOut = UCase(Mid(strIn, 1, 1)) & Mid(strIn, 2)
		end if
	end if

	PCaseWord = strOut
End Function

Open in new window


Don't worry about the extra code in here, it will not affect the result. Also you could use this elsewhere for Proper Casing names.

GH
0
 
coreybryantAuthor Commented:
Just enough ASP code to get myself into trouble :)

I came up with this code but an error:
Syntax error

/quantum/features.html, line 29

Public Function ProperCase(Input)

occurred.  I think I copied over part of what I had.

Thanks!
<% 
Function BreadCrumb(FullPath)

Do Until instr(1,FullPath,"/") = 0
'## Create an array of letters in the alphabet.
Letters = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")

'## split on the /
tmpPath = mid(FullPath,1,instr(1,FullPath,"/")-1)
strTmpPath = Trim(tmpPath)
DirPath = DirPath & strTmpPath & "/"

'## upshift the first character
firstLetter = ucase(mid(strTmpPath,1,1))
strTmpPath = firstLetter & mid(strTmpPath,2,len(strTmpPath))

'## replace udnerscores with spaces and upshift the following character
for each letter in letters
strTmpPath = Replace(Trim(strTmpPath),"_" & lcase(letter)," " & UCase(letter))
next

'## split the next one out	
FullPath = mid(FullPath,instr(1,FullPath,"/")+1,Len(FullPath)-Len(tmpPath))

strPathPart = Replace(Replace(strPathPart, "_", " "), "-", " ")
strPathPart = ProperCase(strPathPart)

'' ## Proper Case (Name Case) a sentance, or name
Public Function ProperCase(Input)
	Dim strOut, astr, i, j, t

	strOut = LCase(Input)
	astr = Split(strOut, " ")

	for i = 0 to UBound(astr)
		if InStr(astr(i), "-") = 0 then
			astr(i) = PCaseWord(astr(i))
		else
			t = Split(astr(i), "-")
			for j = 0 to UBound(t)
				t(j) = PCaseWord(t(j))
			next
			astr(i) = Join(t, "-")
		end if
	next

	ProperCase = Join(astr, " ")
End Function

'' ## Takes a word and Upper-cases the first character, Also deals with "McDonnell", "MacDonalds" and "O'Riley"
'' ## 2010
Function PCaseWord(strIn)
	Dim strOut, t

	t = Mid(strIn, 1, 3)
	if t = "mac" then
		strOut = "Mac" & UCase(Mid(strIn, 4, 1)) & Mid(strIn, 5)
	else
		t = Mid(t, 1, 2)
		if t = "mc" then
			strOut = "Mc" & UCase(Mid(strIn, 3, 1)) & Mid(strIn, 4)
		elseif t = "o'" then
			strOut = "O'" & UCase(Mid(strIn, 3, 1)) & Mid(strIn, 4)
		else
			strOut = UCase(Mid(strIn, 1, 1)) & Mid(strIn, 2)
		end if
	end if

	PCaseWord = strOut
End Function
%>

Open in new window

0
 
G_HCommented:
OK, In your original code, you have "Function" and "End Function". Put the two Functions I provided after your existing "End Function".

ASP is currently complaining because you have a function inside another function (which is not allowed).

GH
0
 
coreybryantAuthor Commented:
This is what I have right now.  No errors this time but nothing is showing.  
<% 
Function BreadCrumb(FullPath)

Do Until instr(1,FullPath,"/") = 0
'## Create an array of letters in the alphabet.
Letters = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")

'## split on the /
tmpPath = mid(FullPath,1,instr(1,FullPath,"/")-1)
strTmpPath = Trim(tmpPath)
DirPath = DirPath & strTmpPath & "/"

'## upshift the first character
firstLetter = ucase(mid(strTmpPath,1,1))
strTmpPath = firstLetter & mid(strTmpPath,2,len(strTmpPath))

strPathPart = Replace(Replace(strPathPart, "_", " "), "-", " ")
strPathPart = ProperCase(strPathPart)

'## replace udnerscores with spaces and upshift the following character
for each letter in letters
strTmpPath = Replace(Trim(strTmpPath),"_" & lcase(letter)," " & UCase(letter))
next

'## split the next one out	
FullPath = mid(FullPath,instr(1,FullPath,"/")+1,Len(FullPath)-Len(tmpPath))

'## separate them with >> symbols
IF strTmpPath = "" THEN
response.write "<a href=""/"" style=""text-decoration:none"">Home Page</a>"
ELSEIF strTmpPath = "Home" THEN
ELSE
response.write " &gt; <a href=""" & DirPath & """ style=""text-decoration:none"">" & strTmpPath & "</a>"
END IF
Loop

IF PageTitle = "" THEN
	response.write " -&gt; Current Page"
ELSE
	response.write " -&gt; " & PageTitle
END IF

End Function 
'' ## Proper Case (Name Case) a sentance, or name
Public Function ProperCase(Input)
	Dim strOut, astr, i, j, t

	strOut = LCase(Input)
	astr = Split(strOut, " ")

	for i = 0 to UBound(astr)
		if InStr(astr(i), "-") = 0 then
			astr(i) = PCaseWord(astr(i))
		else
			t = Split(astr(i), "-")
			for j = 0 to UBound(t)
				t(j) = PCaseWord(t(j))
			next
			astr(i) = Join(t, "-")
		end if
	next

	ProperCase = Join(astr, " ")
End Function

'' ## Takes a word and Upper-cases the first character, Also deals with "McDonnell", "MacDonalds" and "O'Riley"
'' ## 2010
Function PCaseWord(strIn)
	Dim strOut, t

	t = Mid(strIn, 1, 3)
	if t = "mac" then
		strOut = "Mac" & UCase(Mid(strIn, 4, 1)) & Mid(strIn, 5)
	else
		t = Mid(t, 1, 2)
		if t = "mc" then
			strOut = "Mc" & UCase(Mid(strIn, 3, 1)) & Mid(strIn, 4)
		elseif t = "o'" then
			strOut = "O'" & UCase(Mid(strIn, 3, 1)) & Mid(strIn, 4)
		else
			strOut = UCase(Mid(strIn, 1, 1)) & Mid(strIn, 2)
		end if
	end if

	PCaseWord = strOut
End Function
%>

Open in new window

0
 
G_HCommented:
Try this:

 
<%
TheOutput = BreadCrumb("Home Page/" & "example-folder/example_file_name.summut")
Response.write TheOutput

'' ## Function to turn path into Breadcrumbs
Function BreadCrumb(FullPath)
	'' ## Dim everything!
	Dim Output, i, arrFullPath, ThisElement

	'' ## Split the FullPath by slashes
	arrFullPath = Split(FullPath, "/")

	'' ## Loop through the parts
	for i = 0 to UBound(arrFullPath)

		'' ## Proper case this part
		ThisElement = ProperCase(arrFullPath(i))

		'' ## chec k we have a length, if not, it the home page????
		if  len(ThisElement) > 0 then
			Output = Output & ThisElement
		else
			Output = Output & "Home Page"
		end if

		'' ## Only if this is not the LAST one, add the separator
		if i < UBound(arrFullPath) then
			Output = Output & " -> "
		end if

	next

	'' ## Send back the output
	BreadCrumb = Output
End Function 

'' ## Proper Case (Name Case) a sentance, or name
Public Function ProperCase(Input)
	Dim strOut, astr, i, j, t

	strOut = LCase(Input)
	astr = Split(strOut, " ")

	for i = 0 to UBound(astr)
		if InStr(astr(i), "-") = 0 then
			astr(i) = PCaseWord(astr(i))
		else
			t = Split(astr(i), "-")
			for j = 0 to UBound(t)
				t(j) = PCaseWord(t(j))
			next
			astr(i) = Join(t, "-")
		end if
	next

	ProperCase = Join(astr, " ")
End Function

'' ## Takes a word and Upper-cases the first character, Also deals with "McDonnell", "MacDonalds" and "O'Riley"
Function PCaseWord(strIn)
	Dim strOut, t

	t = Mid(strIn, 1, 3)
	if t = "mac" then
		strOut = "Mac" & UCase(Mid(strIn, 4, 1)) & Mid(strIn, 5)
	else
		t = Mid(t, 1, 2)
		if t = "mc" then
			strOut = "Mc" & UCase(Mid(strIn, 3, 1)) & Mid(strIn, 4)
		elseif t = "o'" then
			strOut = "O'" & UCase(Mid(strIn, 3, 1)) & Mid(strIn, 4)
		else
			strOut = UCase(Mid(strIn, 1, 1)) & Mid(strIn, 2)
		end if
	end if

	PCaseWord = strOut
End Function
%>

Open in new window


GH
0
 
coreybryantAuthor Commented:
Just in case Quantum Gateway - right above the border towards the bottom of the page, you will see:
Home Page -> Example-Folder -> Example_file_name.summutHome Page -> Example-Folder -> Example_file_name.summut

It should be:
Home Page -> Quantum Gateway -> Quantum Payment Gateway

The Home Page, the folder is named quantum-gateway, and the page title is Quantum Payment Gateway
0
 
G_HCommented:
So Line 2 above should read:
 
TheOutput = BreadCrumb("Home Page/quantum-gateway/Quantum Payment Gateway")

Open in new window

GH
0
 
coreybryantAuthor Commented:
Thanks - that part is working, but the third section (Page Name) - can it grab the page title so that it says
Home Page -> Quantum-Gateway -> Virtual Terminal
on Virtual Terminal instead of
Home Page -> Quantum-Gateway -> Quantum Payment Gateway

This file include would be (at least) on all the pages in the quantum-gateway folder.

Thank you!
0
 
G_HCommented:
I think I will need to see some more code...

What are you doing / and do you have the page title in a variable?

GH
0
 
coreybryantAuthor Commented:
Right now - it is just <title>Quantum Gateway</title>

From another question, we came up with
<%
Dim pagetitle
pagetitle = "Example Page"
%>
<%=pagetitle%>

Open in new window

So depending on exactly how it is reading the Folder, that could probably be pulled as well.
0
 
G_HCommented:
As long as this comes after line 3 in the code above you can do:

 
TheOutput = BreadCrumb("Home Page/quantum-gateway/" & pagetitle)

Open in new window


GH
0
 
coreybryantAuthor Commented:
I have not tried that just yet but I also have this code
<%
Response.Cookies("mt")("pagetitle") = ""
Server.Execute("/traffic/track.asp")
%>

Open in new window


in the footer (after everything).  Would that help?
Also, if I switch to another folder, it seems like I might need to change the code?
0
 
G_HCommented:
At the moment, I am not sure where you are getting the folder name from. As you have not posted the code for the whole page (I am not suggesting you do), I cannot see what you have got currently.

The code above is fairly easy to change, it is just that one line which needs to be done. I think however it may make more sense to you, if it is re-written as two lines:

 
TheInput = "Home Page/quantum-gateway/" & pagetitle
TheOutput = BreadCrumb(TheInput)

Open in new window


Now, whatever you have, you can put into the variable "TheInput" and the converted version will come out the "TheOutput".

It is possible to do the folder part dynamically, if you do not know the folder for any given page... Is that what you are looking for?

GH
0
 
coreybryantAuthor Commented:
I was hoping to gather the folder name from the folder the page(s) are in quantum-gateway, and have this change it to Quantum Gateway
0
 
G_HCommented:
OK, here is the whole lot again. Only the part at the front has change, and the part which calls the function:

This will work even if you are multiple folders deep (Like: Home Page -> Folder 1 -> Sub Folder 1 -> Page Title)

 
<%
'' ## Your existing Script includes:
pagetitle = "Example Page"

'' ## New Script - to get folder structure dynamically

'' ## Get the Folder and File Name
ScriptURI = Request.ServerVariables("SCRIPT_NAME")
' response.write ScriptURI & "<br />"

'' ## Convert the Folders and File Name into an array
arrScriptURI = Split(ScriptURI, "/")

'' ## Only if we have enough parts to our array
if UBound(arrScriptURI) < 2 then
	response.write "there is no folder"
else
	'' ## Loop Though the SECOND to NEXT-TO-LAST parts (These are te folders)
	for i = 1 to (UBound(arrScriptURI) -1)
		if i > 1 then TheFolders = TheFolders & "/"
		TheFolders = TheFolders & arrScriptURI(i)
	next
end if


'' ## Slightly modified code
TheOutput = BreadCrumb("Home Page/" & TheFolders & "/" & pagetitls)
Response.write TheOutput



'' ## Functions I previously supplied

'' ## Function to turn path into Breadcrumbs
Function BreadCrumb(FullPath)
	'' ## Dim everything!
	Dim Output, i, arrFullPath, ThisElement

	'' ## Split the FullPath by slashes
	arrFullPath = Split(FullPath, "/")

	'' ## Loop through the parts
	for i = 0 to UBound(arrFullPath)

		'' ## Proper case this part
		ThisElement = ProperCase(arrFullPath(i))

		'' ## chec k we have a length, if not, it the home page????
		if  len(ThisElement) > 0 then
			Output = Output & ThisElement
		else
			Output = Output & "Home Page"
		end if

		'' ## Only if this is not the LAST one, add the separator
		if i < UBound(arrFullPath) then
			Output = Output & " -> "
		end if

	next

	'' ## Send back the output
	BreadCrumb = Output
End Function 

'' ## Proper Case (Name Case) a sentance, or name
Public Function ProperCase(Input)
	Dim strOut, astr, i, j, t

	strOut = LCase(Input)
	astr = Split(strOut, " ")

	for i = 0 to UBound(astr)
		if InStr(astr(i), "-") = 0 then
			astr(i) = PCaseWord(astr(i))
		else
			t = Split(astr(i), "-")
			for j = 0 to UBound(t)
				t(j) = PCaseWord(t(j))
			next
			astr(i) = Join(t, "-")
		end if
	next

	ProperCase = Join(astr, " ")
End Function

'' ## Takes a word and Upper-cases the first character, Also deals with "McDonnell", "MacDonalds" and "O'Riley"
Function PCaseWord(strIn)
	Dim strOut, t

	t = Mid(strIn, 1, 3)
	if t = "mac" then
		strOut = "Mac" & UCase(Mid(strIn, 4, 1)) & Mid(strIn, 5)
	else
		t = Mid(t, 1, 2)
		if t = "mc" then
			strOut = "Mc" & UCase(Mid(strIn, 3, 1)) & Mid(strIn, 4)
		elseif t = "o'" then
			strOut = "O'" & UCase(Mid(strIn, 3, 1)) & Mid(strIn, 4)
		else
			strOut = UCase(Mid(strIn, 1, 1)) & Mid(strIn, 2)
		end if
	end if

	PCaseWord = strOut
End Function
%>

Open in new window


GH
0
 
coreybryantAuthor Commented:
OK - thank you very much!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 10
  • 10
Tackle projects and never again get stuck behind a technical roadblock.
Join Now