4
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by Comatose
0

Javascript, at least broswer embedded Javascript can't do this in a standard compliant way; moving to VB section.

0

Well, using VB6 it's really easy: if dir("c:\autoexec.bat", vbnormal) <> vbnullstring then kill "c:\autoexec.bat" . However, this becomes a little different in vbscript (and for some reason, a bit uglier).

dim filesys
Set filesys = WScript.CreateObject("Scripting.FileSystemObject")
If filesys.FileExists("c:\somefile.txt") Then
   filesys.DeleteFile "c:\somefile.txt"
End If
0

In VBScript, Kill won't work. I don't think dir() works in VBScript either. If doing this in VB6 (compiled language) it is strongly recommended that you do NOT compare the result of dir with "". if dir("C:\MyText.txt") <> vbnullstring then is a much better method. Double quotes is what is known as a null string. It uses somewhere in the area of around 8 bytes. vbnullstring is a special constant that is built into VB6, that reduces the memory usage to like 1 byte. This isn't a very big deal for small apps with a couple of strings.... but when you get into recursion, or loops with string processing and checking, it will make a visible difference.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.