PDA

View Full Version : OpenTextFile method...



jjd228
01-14-2002, 11:55 PM
how can i check to see if a file exists before i try to open it? in 'C' i would use _access()
is there something like this in VBScript?

M.S., Comp. Sci.
MCSE+I

nvraghavaraju
01-15-2002, 02:51 PM
Hi,
This will find if the file exists or not and displays the file contents as a message box. Change the filename according to file location. Thanks.

set fs = CreateObject("Scripting.FileSystemObject")
filename = "Give your path here eg:C:\test.txt"

if fs.FileExists(filename) then
set handle = fs.OpenTextFile(filename)
content = handle.ReadAll
handle.close
MsgBox content
else
MsgBox filename & " doesn't exist!"
end if


Raj
<P ID="edit"><FONT class="small">Edited by nvraghavaraju on 01/15/02 08:52.</FONT></P>