Location of script on server

I'm trying to load a text file into a variable in a vbscript.

However, I can't find out where my script actually seems to be - they're both in the same folder on the server, but I get a 'file not found' when I try to load the text file.

A search seems to suggest using WSCript.ScriptFullName, but I get "Object doesn't support this property or method: 'wsh.ScriptFullName'" if I try it.
LVL 10
Who is Participating?
Shift-3Connect With a Mentor Commented:
Hurm.  So you FTP both files to the same folder but the script doesn't recognize that the other file is there?  That is odd.

Perhaps it has something to do with directory permissions, in which case there's nothing you can do about it remotely.

Otherwise you could write a query to search the whole drive for the file, but if it's already not working when they're in the same folder then it's unlikely to help.
If the text file is in the same directory then you should be able to load it with script like the example below.  Customize the value of the strTextFile variable on line 4 with the text file's name.  If it's in a different folder, change the value to a relative or absolute path.

The TriStateUseDefault parameter ensures that it will work even if the text file is Unicode.

Const ForReading = 1
Const TriStateUseDefault = -2
strTextFile = "filename.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(strTextFile, ForReading, False, TriStateUseDefault)
strText = objTextFile.ReadAll

Open in new window

peetmAuthor Commented:

I tried the fso earlier myself, and basically had the same result, e.g., 'file not found'.

I used the fso to find the current folder [as far as the script was concerned] using:


dim fso

set fso = server.createobject("scripting.filesystemobject")

response.write fso.getfolder(".").path


It, like everything else I've tried returns C:\WINNT\system32
What happens if you manually enter the file's absolute path, e.g.

Set objTextFile = objFSO.OpenTextFile("c:\files\textfile.txt", ForReading, False, TriStateUseDefault)

Open in new window

peetmAuthor Commented:
Trouble is, I don't know its abs path.

It's hosted on a server in the USA so all I can do is ftp it up there.  Of course, I could ask their support about this ["where the hell is this thing ...!"], but I though I was just being dumb and that this must happen all of the time to 'web people' - so I thought I'd try EE first.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.