0

I am using the following code to try and find a file contained in another directory from my code file.

Set fi=fs.OpenTextFile(Server.MapPath("~/counter/counter.txt"), 1)

I have also tried.

Set fi=fs.OpenTextFile(Server.MapPath("./root/folder1/counter/counter.txt"), 1)

In either case this should get me back to the counter.txt file. From what I understand ~/ moves up 1 directory and ./ moves up to the root directory.

Both times however I receive an error saying an invalid character has been used. When removing these I get a different error saying the path cannot be found (Which I would expect because it is not a valid path without moving up 1 directory).

What are the valid characters to do the following in VBscript: move up a single directory? move up to the root directory?

Thanks for the help

1 Answer 1

8

A few things:

The tilde character "~" is not valid here.

The single period character "." is for specifying the current directory/folder.

A set of period characters ".." is for specifying the parent directory/folder. For example, to refer to a file found in the parent of the current directory, you might use:

Server.MapPath("../counter.txt")

You can chain these to walk up more than a single parent path. To refer to a file found three directories above the current, you might use:

Server.MapPath("../../../counter.txt")

The documentation on MSDN for the MapPath function outlines this. Pay attention to the caution listed here about enabling parent paths if you want to be able to refer to relative paths above the current directory. If you get an error when trying to refer to a parent path, then you do not have parent paths enabled.

2
  • 4
    +1 Worth pointing out the the "~" is used in ASP.NET to indicate the root folder of the application but ASP classic doesn't suppor this syntax. Jun 28, 2012 at 9:12
  • 2
    +1 In addition, paths which starts with a forward slash "/" refers to the application root like include virtual. At least in IIS7+, am I correct?
    – Kul-Tigin
    Jun 28, 2012 at 14:19

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.