narrator Posted March 8, 2011 Report Share Posted March 8, 2011 Hi,A site I'm developing will have new folders added regularly. Each folder represents a category. I'd like to use the same template file in each new folder. To save editing the template with the category name each time, I'd like to create a variable which takes the category name from the folder name:myurl/category1/mytemplate.asp > variable = "category1"myurl/category2/mytemplate.asp > variable = "category2"myurl/category3/mytemplate.asp > variable = "category3"Any suggestions gratefully received.Thanks. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 8, 2011 Report Share Posted March 8, 2011 You can use a combination of dirname and basename:$dir = basename(dirname($file));Hold on, that was for PHP.If you're using VBScript you'll probably have to get the position of the last slash, remove everything after it (including the slash), then get the position of the new last slash, and return everything after that. So you would strip off the filename and slash, then find the position of the last slash and get everything after it. You can also use split to break the string up in an array, and then get the second to last element in the array:http://www.w3schools.com/VBscript/func_split.aspJavascript would be similar, Javascript has a split method for strings that will split the string up the same way: var file = 'myurl/category1/mytemplate.asp';var chunks = file.split('/');var dir = chunks[chunks.length-2]; Link to comment Share on other sites More sharing options...
narrator Posted March 23, 2011 Author Report Share Posted March 23, 2011 Thanks Just...Attempting to use your reply.Struggling, but I understand what the idea.I'll let you know how I get on. Link to comment Share on other sites More sharing options...
narrator Posted March 23, 2011 Author Report Share Posted March 23, 2011 (edited) Found an easy way to do what I wanted<%Dim fs,fo,catSet fs=Server.CreateObject("Scripting.FileSystemObject")Set fo=fs.GetFolder(server.MapPath("."))cat=fo.nameset fo=nothingset fs=nothing%>Tested and seems to work. <%=cat%> produces the current folder name.Does anyone think the above code could create unknown problems?Thanks Edited March 23, 2011 by narrator Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now