Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I delete a Directory that is 1

Status
Not open for further replies.

IonelBurtan

Programmer
May 25, 2001
601
RO
How do I delete a Directory that is NOT empty (has subdirectories and files)?
I do not want to use the native RmDir and Kill, because is too messy for me.
I'd like a single api call, if posible, without opening any DOS window (not like calling the MSDOS rd /s /q)

TNX


s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
U can use the FileSystemObject and use its method
if fso.folderexists(path of folder) then
fso.deletefolder "path of folder"
endif

fso is the FileSystemObject

It might help
 
Tnx, but I do not want to link to any supplimentary reference. (like scrrun.dll as u say for FileSystemObject). FSO might work, but I am wandering if I really need to use other DLL

For example I could use de Delete method of a Win32_Directory object from WMI but this would force me to use WMI and link to other dll.

I would like to use a Declare function for this purpose.

TNX

s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
>I do not want to link to any supplimentary reference

May I ask why not?
 
Because the program I am working at is an utility and I do not want t o make a setup for it. I just want to copy it there and that is it.

Do u know a API that I can use, so that I won't have to mess around with other dlls and versions problems and regsvr32 & stuff.

Ionel

s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
You do realise that the scripting runtime is included in W98, W2000, XP, W2003, IE5 and later, Office 2000 and later, so it is actually pretty unlikely nowadays that your target machine won't already have the runtime, so you wouldn't have to distribute it...
 
Yes, I know that, but I also know that are different versions of scrrun.dll, and from my previous experiences they are not fully compatible. I had the surprise to have one program running ok on a machine win Win2000 and giving a scrrun related error on other with Win NT4.0. When I checked I saw that it was an older version of scrrun.dll. After i replaces the file and re-regsvr32 it, the problem disapearred.

So, if u please know an OS or Shell API , that will do the job of deleting a NOT empty directory, please let me know

Ty 4 the comment,

s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
Put this code in a bas module:
Code:
Option Explicit

Public Type SHFILEOPSTRUCT
    hwnd As Long   'The handle of the window calling the function
    wFunc As Long   'One of the FO_ constants below
     pFrom As String   'Path and file name of the file to acted on. Usual wildcards allowed
    pTo As String   'Destination path/filename for move, copy and rename operations
    fFlags As Integer  'Additional options - not fully documented
    fAnyOperationsAborted As Long  'No information on this flag
    hNameMappings As Long  'No information on use.
    lpszProgressTitle As String    'Only used if FOF_SIMPLEPROGRESS is not specified
End Type

Public Declare Function SHFileOperation Lib _
"shell32.dll" Alias "SHFileOperationA" _
(lpFileOp As SHFILEOPSTRUCT) As Long

' wFunc - type of operation constants. Assign one of these to wFunc
Public Const FO_MOVE = &H1
Public Const FO_COPY = &H2
Public Const FO_DELETE = &H3
Public Const FO_RENAME = &H4

' fFlags - can be OR'd together to provide extra options when the file operation is executed
Public Const FOF_MULTIDESTFILES = &H1
Public Const FOF_CONFIRMMOUSE = &H2
Public Const FOF_SILENT = &H4   'don't create progress/report
Public Const FOF_RENAMEONCOLLISION = &H8
Public Const FOF_NOCONFIRMATION = &H10    'don't prompt the user.
'fill in SHFILEOPSTRUCT.hNameMappings Must be freed using SHFreeNameMappings
Public Const FOF_WANTMAPPINGHANDLE = &H20
Public Const FOF_ALLOWUNDO = &H40   'sends a file to the recycle bin instead of permanently deleting it
Public Const FOF_FILESONLY = &H80       'on *.*, do only Files -Not directories
Public Const FOF_SIMPLEPROGRESS = &H100   'don't show names of files during the operation
Public Const FOF_NOCONFIRMMKDIR = &H200   'don't confirm making any needed directories

Here's a quick example that sends the folder, n:\scratch, to the recycle bin. You can Or together various flags in the fFlags member of the SHFILEOPSTRUCT structure to determine if confirmation is requested, sent to recycle/deleted, progress displayed etc.

Code:
Private Sub Command1_Click()

    Dim lngRtn As Long
    Dim udtSHF As SHFILEOPSTRUCT
 
    udtSHF.hwnd = Me.hwnd
    udtSHF.wFunc = FO_DELETE
    udtSHF.pFrom = "n:\scratch"
    udtSHF.fFlags = FOF_ALLOWUNDO

    lngRtn = SHFileOperation(udtSHF)

End Sub

Paul Bent
Northwind IT Systems
 
Works just fine, my friend. With few little adjustments i obtained what i wanted .

Ty so much!

s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top