Page 1 of 1

delete folder function, only possible with vb-script ?

Posted: Mon Feb 26, 2007 9:09 am
by emu99
Hi,

is there a possibility to remove complete folders ?
I can't find a function for deleting folders... like "delete files".

E.g. I need to delete a folder inside folder SHORTCUTFILES after a installation created a folder with links.

Since we don't want programs to create their own shortcuts on the clients uf our users, because we use a central shortcuts on a fileserver for which users are each permitted by Acitve Directory-Group...

The Installation itself is executed inside the project with the run program function, since no msi-package available of JDK 5.02 EE.

@Installaware: could be something for next version / Designrequest
:)

Best Regards
Emu

workaround with vbs

Posted: Mon Feb 26, 2007 10:33 am
by emu99
i managed to create a workaround with a vbs which can take a parameter which holds the path + foldername and added the vbs under supportfiles...

so now i call run program with $WINSYSDIR$\\cscript.exe and parameter $SUPPORTDIR$\\removefolder.vbs $WINSYSDIR$test (as e.g. to delete folder test inside system32)

But i wonder why a such often used function like deletefolder is not inside the regular functions of installaware. Or I'm just blind and can't find it :-)

removefolder.vbs:

On Error Resume Next
Set objArgs = WScript.Arguments
Set WshShell = WScript.CreateObject("WScript.Shell")
Set fso = WScript.CreateObject("Scripting.FileSystemObject")

fldr = objArgs(0)

If fso.FolderExists(fldr) Then
fso.DeleteFolder fldr, True
End If

Set fso = Nothing
Set WshShell = Nothing
Set fso = Nothing

WScript.Quit(0)

Posted: Tue May 15, 2007 4:07 am
by dmostert2
Yes - I agree with you. It shouldn't be so difficult to remove a folder's contents and afterwards the folder as well :?:


Cheers,
D.

Posted: Tue May 15, 2007 9:10 am
by davidda
It isn't difficult. :P

Just use the Run Program function to run cmd with the parameters /C "rd /S /Q "c:\\DirToDelete""

Posted: Tue May 15, 2007 12:45 pm
by dmostert2
:P Very clever - but will this work on Vista and UAC?

D.

Posted: Tue May 15, 2007 1:54 pm
by MichaelNesmith
Delete Files Recursive, anyone?

Posted: Tue May 15, 2007 2:18 pm
by davidda
Michael i don't think this would help, because they don't want to only delete the files in the folder, but the folder itself.

I don't know if it works on Vista or UAC (what's that?), because i have none of them here.

Posted: Tue May 15, 2007 2:37 pm
by MichaelNesmith
Use Call DLL Function on RemoveDirectoryA in kernel32.dll if you want to remove a folder that is already empty.

Re: delete folder function, only possible with vb-script ?

Posted: Fri Sep 17, 2010 1:48 pm
by JohnGalt
There should be a script command for this. I know that Windows Installer does it, it's not hard there, so this is just an oversight! Please add this feature!

Re: delete folder function, only possible with vb-script ?

Posted: Fri Sep 17, 2010 7:34 pm
by mills
The request for this feature has been noted.

In the mean time, to delete a folder, you'll need to:

Delete the contents of the folder:
Recursively Delete Files $path$\folder

Delete the (empty) folder:
Call DLL Function kernel32.dll->RemoveDirectoryA

Re: delete folder function, only possible with vb-script ?

Posted: Thu Dec 01, 2011 1:00 pm
by ckaware
What's the status on this feature request? I uninstall my application and the TOMCAT folder left behind has a ton of EMPTY sub directories.

Re: delete folder function, only possible with vb-script ?

Posted: Thu Dec 01, 2011 7:36 pm
by giaviv
Chris,

For now, please use the workaround above.

Re: delete folder function, only possible with vb-script ?

Posted: Tue Feb 14, 2012 6:53 pm
by John Mc
I appreciate the work around, but I'd like to check an alternate solution. Can you:

1) Recursively Delete Files "$path$\folder\*"
2) Recursively Delete Files "$path$\FileNameThatDoesNotExist.not"


Assumptions:
1) I want to delete all empty folders under $path$2) I'm confident that no files exist with the name given above


Thanks!

Re: delete folder function, only possible with vb-script ?

Posted: Wed Feb 15, 2012 12:06 am
by giaviv
Hi,

How about you give it a try? Which version of IA are you using?

Re: delete folder function, only possible with vb-script ?

Posted: Wed Feb 15, 2012 12:53 pm
by John Mc
I tested it out and everything seemed to work fine. We'll see how things go in a more complex environment, but I'm happy enough to go with it.

I'm using IA 12 Studio on Win 7.

Thanks,