469,568 Members | 1,397 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

Is it relative, or is it absolute?

164 Expert 100+
I have a script that looks for certain characters in a file path string to decide whether the string is an absolute filepath, or a relative one. My question is, does anyone have a cleaner way of doing this which is not error prone based on the operating system?

Here is what I have, but this would not work if someone installed an ASP component on, say, a Unix box.

Expand|Select|Wrap|Line Numbers
  1. '//----------------------------------------------------
  2. '// was physical or relative path specified?
  3. '//----------------------------------------------------
  4. if mid(sourceFilePath, 2, 2) = ":\" then
  5.    sAbsoluteInputPath = sourceFilePath
  6. else
  7.    sAbsoluteInputPath = server.mappath(sourceFilePath)
  8. end if
  9.  
I had thought something could be done using the Server Variable: APPL_PHYSICAL_PATH:, basically looking to see if APPL_PHYSICAL_PATH: is InStr() of the path tested.

Ideas, suggestions?
Dec 6 '07 #1
2 1031
Nicodemas
164 Expert 100+
Turns out, as I was writing this, the following struck me. Seems immune to any errors in operating system file path format differences (my last solution was vulnerable):

Expand|Select|Wrap|Line Numbers
  1. '//----------------------------------------------------
  2. '// was physical or relative path specified?
  3. '//----------------------------------------------------
  4. if instr(sourceFilePath, request.servervariables("APPL_PHYSICAL_PATH")) > 0 then
  5.    sAbsoluteInputPath = sourceFilePath
  6. else
  7.    sAbsoluteInputPath = server.mappath(sourceFilePath) 
  8. end if
  9.  
Dec 6 '07 #2
Nicodemas
164 Expert 100+
and if you wanted a global solution, you could function-ize it:


Expand|Select|Wrap|Line Numbers
  1. function isPhysicalPath(myPath)
  2.    isPhysicalPath = instr(myPath, request.servervariables("APPL_PHYSICAL_PATH")) = 1
  3. end function
  4.  
Dec 6 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Joe Cybernet | last post: by
2 posts views Thread by Catherine Lynn Wood | last post: by
3 posts views Thread by Markus Ernst | last post: by
7 posts views Thread by Rizaan Jappie | last post: by
6 posts views Thread by openleren | last post: by
8 posts views Thread by JJ | last post: by
15 posts views Thread by Lars Eighner | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.