Finding the 'root' level?

R

Robb Meade

Hi all,

I've written a small form handler script which should work for 'all' (term
used loosely) forms...

It will email the company, send courtesy emails to the form filler and save
data to a text file - all with various options made easy by changing hidden
tags in the form.

One minor problem I've come across is that I need to be able to write to a
specific directory on the server.

So lets say I allow a hidden tag for the owner of the server to enter the
name of the directory they want to write to, lets call it 'data'.

When I use the Server.Mappath('data') in this scenario, it looks within the
same directory, as a result it does not find the directory, and then my
script creates one.

The actualy directory (in the current case) is say one level above (../
etc), but I dont know that that is always going to be the case.

I'd rather not have to put the script in the root level of the web for this
to always work, as for frontpage users for example they may have subwebs and
so on, but the data folder could well be in the main root directory.

So, how can I ensure that using the Server.Mappath('data') find the 'data'
folder at the root level.

I appreciate on my setup here I could simply enter the full path, ie,
E:\webs\webdev\some-client\data but I need 'joe public' to be able to enter
just the name of the directory (or use the default of 'form-data' or
something), and have it written to the correct place.

Anybody got any ideas/suggestions?

Thanks in advance for any help,

Regards

Robb Meade
 
A

Aaron Bertrand - MVP

Have you tried something like this:

set fso = server.createobject("Scripting.FileSystemObject")
if fso.folderExists(server.mappath("/") & "data") then
' folder exists in root!
end if
set fso = nothing


Not sure if it needs to be "\data" -- I always forget the behavior of
server.mappath. I could have tested it in the time it took me to state
that, but I'm lazy today...
 
T

Tom B

Doesn't Server.MapPath("\Data\File.txt") return relative to the root?
What happens if your users enter the same name? Say "Data"?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top