tags:

views:

623

answers:

7

Hello

I'm trying to read remote text files using this code:

function defdate(ipaddress)
  deffilePath = chr(34) & "\\" & ipaddress & "\c$\" & deffileName & chr(34)
  wscript.echo deffilePath
  set deffile = objFSO.OpenTextFile(deffilePath)
  do while not deffile.endofstream
    s=deffile.readline    
    wscript.echo s
  loop
deffile.close
end function

My deffilePath below expands into strings like this:

"\\10.211.19.207\c$\Program Files\Common Files\Symantec Shared\VirusDefs\definfo.dat"

However, I get "Microsoft VBScript runtime error: Bad file name or number".
What could be the problem?

A: 

I think you need two backslashes at the start of an UNC pathname. Try adding another one!

My guess would be that it works with "\\10.211.19.207\c$\Program Files\Common Files\Symantec Shared\VirusDefs\definfo.dat".

sirprize
Well spotted, but I just missed that when I copied the text. I do have two backslashes
qaz22
OK, then I'm afraid I don't know what the problem is. Good luck anyway! :)
sirprize
A: 

Is c$ not the problem?

PoweRoy
No, the problem is the missing backslash. "c$" is the name of the hidden share that Windows creates by default for the "c:" drive.
andynormancx
Andy, the backslash isn't missing -- that's a rendering problem.
Roger Lipscombe
I know that now Roger, I commented before you fixed that.*waves*
andynormancx
A: 

Have you tried removing the chr(34) at the end?

ck
Whoever -1 me, add it back. I was right, I just missed the chr(34) at the beginning should be removed as well.
ck
+1  A: 

You don't need to (read: "must not") enclose your path in quotes.

deffilePath = "\\" & ipaddress & "\c$\" & deffileName
Tomalak
+1  A: 

You only need to include the quotes -- the CHR(34) -- when using the command-line, or for similar APIs. If a method takes just a filename, leave them out.

Roger Lipscombe
+1  A: 

The problem is the "chr(34)" at the beginning and the end. When typing a path in the Windows run menu you need those quotes, but when passing a path to a function call like this you don't want them.

andynormancx
A: 

Thanks everyone, the extra enclosing quotes was the problem.

qaz22
You should accept one of the answers, then.
Tomalak