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
peetmAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shift-3Commented:
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
objTextFile.Close

Open in new window

0
peetmAuthor Commented:
@Shift-3

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
0
Shift-3Commented:
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

0
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.

Thanks.
0
Shift-3Commented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.