Click to See Complete Forum and Search --> : Looking up one level in a directory structure (..)
mousebear
08-11-2006, 10:57 AM
I have some code that I have working just fine, but I could not figure out how to use the equivalent of ".." in ASP to look one level up in the directory structure. I got an error message telling me I was using illegal characters. So in the mean time I start the path from the root, which works, but is not ideal.
The beginning portion of the Code is as follows:
Function kc_fsoFiles(folderName, IncludeExtension)
Dim theFolder : theFolder = Server.MapPath(folderName)
Dim rsFSO, objFSO, objFolder, File
Const adInteger = 3
Const adDate = 7
Const adVarChar = 200
Set rsFSO = Server.CreateObject("ADODB.Recordset")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(theFolder)
Set objFSO = Nothing
...
Is there a way to look up one level in the directory structure in ASP?
russell
08-11-2006, 11:56 AM
../
See FSO method:
GetFolder() method
.ParentFolder property
but i have to disagree with you. starting from the root IS ideal. it is absolutely the best way to do it -- using relative paths from the root such as
/cars/ford/mustang/engines.asp
this is always preferable to slash-dotting your way around, whether it be links, include directives or paths passed to server.mappath
mousebear
08-12-2006, 01:17 PM
Interesting. I'll check out .ParentFolder.
I thought I had been universally recommended to use relative paths. I am going to reconsider. I could change the directory structure for my localhost to match the absolute path that our service provider uses, so that the absolute path would work live and for my local development environment. I thought the big advantage to the relative paths was that you could change the directory structure and still find the files. Also, if my service provider changes their directory structure, then we would have to repath all our files. I doubt they would do this because of the disruption it would cause though.
Any more opinions/responses to this?
russell
08-12-2006, 11:19 PM
you want to use relative paths, but relative to the root -- not the current file. Why? becuae u can move files around, copy/paste code, have include files that work from anywhere in your site. it beomes a maintenance nightmare on large sites to use paths relative to the current file. it is also a minor security risk to slash-dot paths if you slash-dot your way out of the webroot.
and no -- if they change their structure, your site's virtual root remains the same, so u make no code changes at all.
mousebear
08-13-2006, 10:22 AM
Thanks,
Well, I've done what you have suggested, at least for my .ASP files. What my hosting site has is two levels of directories below their root. Our site's top level information goes down at \level1\level2\ourstuff\. To ASP, the root is above level1. I can see those levels, but I can't put our information there, and I wouldn't want to. What I had to do in Windows XP on our local machine was rename our virtual web server "level1" (not using real names here) and redefine it's reference to a spot in our local directory structure, then add a directory called "level2" below that, then start with all of our "root-level" files (like index.html) below that. It all works, and the ASP on the public server sees the same filename paths as we do on our local development machine.
So I did not end up using .ParentFolder, but I did learn about file and folder properties in ASP that I might find useful in the future.
I see your point about finding things from anywhere within your site. If you move the target file that is not going to work though, and if you move the source and target file together, the slash-dot paths still work. Sticking to all slash dots, I have been pretty restricted as to what levels I was putting all my information into, so that I wasn't deviating too much from our templates. I want future amateur administrators to be able to copy and modify pages, and not get lost because their slash-dot paths are looking to the wrong level.
russell
08-13-2006, 05:20 PM
may want to have a look at this thread (http://www.webdeveloper.com/forum/showthread.php?t=110351) where i gave a more detailed explanation to a similar issue. the main benefit of using paths relative to the root of the site is that u can move files (or even create 'em without knowing where in the site they will be deployed) and everything still works.