DELET TEXT FILE

K

karpagam

Hi

Can any one help me to find correct command to delete text
file. I used KILL File name it works in VBA but it is not
working in VBS file


Please give some hint


karpagam
 
I

ivv

'************************************************
' File: File3.vbs (WSH sample in VBScript)
' Author: (c) G. Born
'
' Copying and deleting files
'************************************************
Option Explicit

Const path = "C:\Born" ' Test folder (must exist)
Const file1 = "C:\Born\Test.txt" ' Source file (must exist)
Const file2 = "C:\Born\Test1.txt" ' Target file

Dim Text, Title, i
Dim fso, oFile, oFolder ' Object variables

Text = "File copied" & vbCrLf
Title = "WSH sample - by G. Born"

' Create FileSystemObject object to access file system.
Set fso = CreateObject("Scripting.FileSystemObject")

' Check whether file exists.
If (fso.FileExists(file1)) Then
' Copy file1 to file2 (or use fso.CopyFile file1, file2).
Set oFile = fso.GetFile(file1) ' Get File object.
oFile.Copy file2, True ' Overwrite existing target.

Set oFolder = fso.GetFolder(path)
Set oFile = oFolder.Files ' Get Files collection.
For Each i In oFile ' All files
Text = Text & i.Name & vbCrLf
Next

MsgBox Text, vbOKOnly + vbInformation, Title
Else
WScript.Echo "File " & file1 & " doesn't exist"
WScript.Quit
End If

' Delete file upon request.
If (MsgBox("Delete file?", vbYesNo, Title) = vbYes) Then
Set oFile = fso.GetFile(file2) ' Fetch File object.
oFile.Delete ' (or use fso.CopyFile file2)
WScript.Echo "File " & file2 & " deleted"
End If

'*** End
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top