| | |
Need to delete a file
![]() |
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). Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
dim filesys Set filesys = WScript.CreateObject("Scripting.FileSystemObject") If filesys.FileExists("c:\somefile.txt") Then filesys.DeleteFile "c:\somefile.txt" End If
Last edited by Comatose; Jan 11th, 2009 at 1:58 am.
Hi,
use KILL:
Regards
Veena
use KILL:
vb Syntax (Toggle Plain Text)
If Dir("C:\MyText.txt") <> "" Then Kill "C:\MyText.txt" End If
Regards
Veena
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. ![]() |
Similar Threads
- Can't delete file on harddrive! (C++)
- can't delete file need help please (Windows NT / 2000 / XP)
- Cannot delete file (Windows 95 / 98 / Me)
- Can't Delete File!!! (Windows NT / 2000 / XP)
- Explorer 'crashes' when trying to delete a file (Windows NT / 2000 / XP)
- cannot delete file/file in use by other program (Windows NT / 2000 / XP)
- cannot delete file (Windows NT / 2000 / XP)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: how can i send a folder through email
- Next Thread: Unicode in vb6.0
| Thread Tools | Search this Thread |
* 6 2007 access activex add age basic beginner birth bmp calculator cd cells.find click client code college connection connectionproblemusingvb6usingoledb creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit excel excelmacro file filename form header iamthwee image inboxinvb internetfiledownload listbox listview liveperson login looping microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading remotesqlserverdatabase report save search sendbyte sites sql sql2008 sqlserver subroutine tags time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web windows






