|
-
Nov 25th, 2000, 10:29 AM
#1
Thread Starter
Ex-Super Mod'rater
How do you delete files using VB???
Thanx for any help!!
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Nov 25th, 2000, 10:32 AM
#2
Hyperactive Member
you use the kill statement ... like:
kill "c:\filename.exe"
-
Nov 25th, 2000, 10:36 AM
#3
Thread Starter
Ex-Super Mod'rater
Thanx
Thats what I was trying but I had one slight problem:
I did this:
Code:
Msgbox FileSystem.Kill ("C:\Temp123456789.txt")
I thought it was a boolean function which would say if it worked or if it failed.
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Nov 25th, 2000, 01:07 PM
#4
Hyperactive Member
If it didn't work it will return an error.
You would have to do something like this:
Code:
On Error Goto ErrHandle
Kill ("C:\Temp123456789.txt")
Exit Sub
ErrHandle:
Msgbox "There was an error."
-
Nov 25th, 2000, 04:16 PM
#5
This thread may be of interest to you as well.
-
Nov 25th, 2000, 05:27 PM
#6
Fanatic Member
API?
You can also use the API to get some extra effects....
Code:
Private Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As Long
End Type
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Const FO_DELETE = &H3
Private Const FOF_ALLOWUNDO = &H40 ' if this flag included files will be sent to the recycling bin
Private Const FOF_SILENT = &H4 ' if this flag is included then the progress screen will not be displayed
Private Const FOF_NOCONFIRMATION = &H10 ' if this flag is included then the user will not be asked to confirm the files to be deleted
Public Sub cmdDelete_Click()
Dim lRet As Long
Dim fFileStruct As SHFILEOPSTRUCT
With fFileStruct
.wFunc = FO_DELETE
' You can also delete multiple files by passing a string variable in this format "C:\Windows\text.txt" & vbNullChar & "C:\Windows\text2.txt"
.pFrom = "C:\Windows\Text.txt"
'Include next line of code if you want to send files to the recycling bin
'.fFlags = .fFlags Or FOF_ALLOWUNDO
'Include the next line of code if you do not want the progress of the files being deleted
'.fFlags = .fFlags Or FOF_SILENT
'Include the next line of code if you want a screen that says "Are you sure you want to delete this file" to come up
'.fFlags = .fFlags Or FOF_NOCONFIRMATION
End With
lRet = SHFileOperation(fFileStruct)
if lRet = 0 then
MsgBox "File(s) not deleted"
end if
End Sub
Also a MessageBox will be automatically displayed if you try to delete a file that is currently in use.
[Edited by YoungBuck on 11-25-2000 at 05:29 PM]
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|