|
-
Jul 18th, 2002, 04:33 PM
#1
Thread Starter
Hyperactive Member
how to delete one file?
How do I delete a file through vb?
-
Jul 18th, 2002, 04:38 PM
#2
Fanatic Member
Well..
Just type Kill and the pathname
Hope this helps.
-Jeremy
-
Jul 18th, 2002, 04:57 PM
#3
PowerPoster
Well
This maybe extreme but gives you the option of the recycle bin
VB Code:
Option Explicit
Private Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAborted As Boolean
hNameMaps As Long
sProgress As String
End Type
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Const FOF_NOCONFIRMATION = &H10 ' Don't prompt the user.
Const FOF_NOCONFIRMMKDIR = &H200 ' don't confirm making any needed dirs
Const FO_COPY = &H2
Const FO_DELETE = &H3
Const FOF_ALLOWUNDO = &H40
Const FOF_FILESONLY = &H80
Public Function NUKILL(PATH As String, Optional RECYCLE As Boolean = True) As Boolean
' NUCLEUS
' DELETE FILE(S) OR FOLDER(S) (INCLUDING SUBDIRECTORIES) AND OPTIONALLY SEND TO RECYCLE BIN
' IN: PATH OF FILE/FOLDER
' OUT: BOOLEAN INDICATING SUCCESS
If Right(PATH, 1) = "\" Then PATH = Left(PATH, Len(PATH) - 1)
If Len(Dir$(PATH)) <> 0 Or Len(Dir$(PATH, vbDirectory)) <> 0 Then
Dim SHFileOp As SHFILEOPSTRUCT
With SHFileOp
' DELETE THE FILE
.wFunc = FO_DELETE
' SELECT THE FILE
.pFrom = PATH
.fFlags = FOF_NOCONFIRMATION Or FOF_FILESONLY
' NEXT OPTIONALLY ALLOW MOVE TO RECYCLE BIN
' WHICH ONLY WORKS FOR WHOLE FOLDERS OR SINGLE FILE OPERATIONS
' IT WILL NOT SEND *.* OR *.TXT TO RECYCLE BIN
' DUE TO BUILT-IN LIMITATIONS IN API FUNCTION
If RECYCLE Then .fFlags = .fFlags Or FOF_ALLOWUNDO
End With
' PERFORM FILE OPERATION
NUKILL = (SHFileOperation(SHFileOp) = 0)
End If
End Function
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Jul 18th, 2002, 05:08 PM
#4
Hyperactive Member
Add reference to Microsoft Scripting Runtime and use File System Objects. However, after seeing Jim's comment about Recycle Bin, I tested this & the file is NOT put into Recycle Bin.
VB Code:
Dim fso As FileSystemObject
Dim strFileName As String
strFileName = "c:\temp\Junk1.txt"
Set fso = New FileSystemObject
fso.DeleteFile strFileName
Nate
-
Oct 11th, 2002, 08:35 PM
#5
Fanatic Member
easy
Kill "C:\example.exe"
you can always change the directory. dont use this maliciously thanks
-
Oct 11th, 2002, 08:37 PM
#6
PowerPoster
Re: easy
Originally posted by duc
Kill "C:\example.exe"
you can always change the directory. dont use this maliciously thanks
Why are you digging up old threads?
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
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
|