Need to delete a file

Reply

Join Date: Jan 2009
Posts: 3
Reputation: sumit-saini is an unknown quantity at this point 
Solved Threads: 0
sumit-saini sumit-saini is offline Offline
Newbie Poster

Need to delete a file

 
0
  #1
Jan 10th, 2009
i want to delete a file from a specific location, if file Existing ; using JavaScript or VB scripting
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,581
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 461
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Need to delete a file

 
0
  #2
Jan 11th, 2009
Javascript, at least broswer embedded Javascript can't do this in a standard compliant way; moving to VB section.
Last edited by ~s.o.s~; Jan 11th, 2009 at 2:08 am.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Need to delete a file

 
0
  #3
Jan 11th, 2009
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)
  1. dim filesys
  2. Set filesys = WScript.CreateObject("Scripting.FileSystemObject")
  3. If filesys.FileExists("c:\somefile.txt") Then
  4. filesys.DeleteFile "c:\somefile.txt"
  5. End If
Last edited by Comatose; Jan 11th, 2009 at 1:58 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: Need to delete a file

 
0
  #4
Jan 12th, 2009
Hi,
use KILL:

  1. If Dir("C:\MyText.txt") <> "" Then
  2. Kill "C:\MyText.txt"
  3. End If

Regards
Veena
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Need to delete a file

 
0
  #5
Jan 12th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC