|
-
Aug 18th, 2000, 02:02 AM
#1
Thread Starter
Hyperactive Member
Is their a way I can do something like a Kill statment but on a folder. In other words delete a folder no questions asked, and it does not put it in the recycle bin?
-
Aug 18th, 2000, 02:29 AM
#2
Add a FileListBox and a Command Button
Code:
Private Declare Function RemoveDirectory Lib "kernel32" Alias "RemoveDirectoryA" (ByVal lpPathName As String) As Long
Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
Private Sub Command1_Click()
For i = 0 To File1.ListCount - 1
DeleteFile (File1.Path & "\" & File1.List(i))
Next
Call RemoveDirectory("c:\windows\desktop\blank\")
End Sub
Private Sub Form_Load()
File1.Path = "c:\windows\desktop\blank"
'replace that with the path of your folder
End Sub
-
Aug 18th, 2000, 05:34 AM
#3
-
Aug 18th, 2000, 07:24 AM
#4
_______
<?>
another alternative is the FileSystemObject
[code]
'using FileSystemObject to delete a folder
Dim myFso As Object
Set myFso = CreateObject("Scripting.FileSystemObject")
myFso.DeleteFolder "C:\yourfolder"
Set myFso = Nothing
[code]
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 18th, 2000, 10:59 AM
#5
I dont like to use FSO because that is another DLL you have to distribute,
and Batman:
I would have used pure VB, but as Yonaton said, API is much faster, and if the folder contained a lot of files VB would be too slow,
and anyway, all VB functions are, are API calls in discuise...
BTW: does anybody know how to get a listing of files in a directory, Without using the FileListBox???
-
Aug 18th, 2000, 02:01 PM
#6
Guru
[/code]denniswrenn: To list the files you can either use the APIs FindFirstFile and FindNextFile, or use the VB function Dir.
You might prefer the API because it's much much faster... Look in the MSDN, because in this special case, I hate it. 
Here's a Dir example, lists all the files in "C:\Windows" in a NORMAL ListBox called List when you click a button called Command1.
Code:
Option Explicit
Private Sub Command1_Click()
Dim sFileName As String
Call List1.Clear
sFileName = Dir("C:\Windows\") ' Initiate search... API equivalent: FindFirstFile
Do
Call List1.AddItem(sFileName)
sFileName = Dir ' Continue search... API equivalent: FindNextFile
Loop Until sFileName = vbNullString ' Returns vbNullString when search is done
End Sub
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
|