cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
james_decosta
Level 9

how to delete some folders using custom code

hi,
i want to delete some folders in the $USER_INSTALL_DIR$ using custom code in the install task or post install task .
Can anyone provide some suggestion and some sample code for deleting the folders in the $USER_INSTALL_DIR$ say FIRST FOLDER ,SECOND FOLDER in the install task or in the post install task by executing custom code to achieve this.
Labels (1)
0 Kudos
(14) Replies
pv7721
Level 20

I'm not sure why you would need custom code in order to delete folders, you've got built-in actions for that.
0 Kudos
james_decosta
Level 9

hi,
i would like to know where i will be able to find the delete file\folder action in the post install task.
And say i want to write custom code for achieving this,isnt it possible to delete a folder in the post install task using custom code action
AND if possible it would be a pleasure to get sample code for doing this.
0 Kudos
pv7721
Level 20

If the delete file/folder is not available in the post-install task, then why can't you use in the install task (see your initial question). What is your IA version?
0 Kudos
james_decosta
Level 9

hi,
can i get some custom code action for deleting folders .
Hi i want to delete some folders which get cached(say) after installation
.Can anyone provide some sample custom code action for deleting folder.
Regards,
James
0 Kudos
purcellk24
Level 7

A Google search will find an example for deleting a directory.

Here's one result...
http://www.exampledepot.com/egs/java.io/DeleteDir.html
0 Kudos
pv7721
Level 20

James, why would you like to complexify your tasks whenever there are easier workarounds. Ok, so the Delete Files / Folders actions are not available in Post-Install task, but Execute Commands are too! So instead of writing custom code, what prevents you from executing commands like:

CMD /C DEL /F /Q "$TEMP_DIR$ (for Windows) or

sh -c "rm -rf $TEMP_DIR$" for Unices.

Ok, I don't deny, writing custom code would mean that you always execute the same code on any of your platforms, but compare these one-liners with the task of writing, testing and integrating the custom code.
0 Kudos
Kondalarao_n
Level 3

public void uninstall(UninstallerProxy arg0) throws InstallException
{
try
{
uninstallDir = "Uninstall";
String buttonValue=arg0.substitute("$CHOSEN_DIALOG_BUTTON$");
System.out.println("button value is --- "+buttonValue);
if(0==Integer.parseInt(buttonValue))
deleteDirectory(arg0.substitute("$USER_INSTALL_DIR$"));
else
deleteDirectory(new File(arg0.substitute("$USER_INSTALL_DIR$")));

productName = arg0.substitute("$PRODUCT_NAME$");
System.out.println("product name is -----" + productName);
File file = new File(arg0.substitute("$USER_INSTALL_DIR$"));
//if (file.isDirectory() && file.list().length > 0)
file.deleteOnExit();
}
catch (Exception ioe)
{
System.out.println(ioe.getMessage());
}
}

/**
* Delete the specified directory represented by directoryToDelete.
* If the directory is not empty, its contents are deleted recursively
* before it is removed.
*/
public void deleteDirectory(String directoryToDelete) throws IOException
{
// fis = new FileOutputStream(f);

try
{
searchDirectory(new File(directoryToDelete));
}
finally
{
// fis.close();
}
}

/**
* Delete the specified directory represented by directoryToDelete.
* If the directory is not empty, its contents are deleted recursively
* before it is removed.
*/
public void searchDirectory(File directoryToDelete) throws IOException
{

// make sure it's a directory

if (directoryToDelete.isDirectory())
{

String fileSep = System.getProperty("file.separator");

String[] filesAndDirs = directoryToDelete.list();

int numberOfFiles = filesAndDirs.length;
if (directoryToDelete.getName().equals("lib"))
{

deleteDirectory(directoryToDelete);

}

for (int i = 0; i < numberOfFiles; i++)
{

File currentFile = new File(directoryToDelete.getPath() + fileSep + filesAndDirs);

if (currentFile.isDirectory())

searchDirectory(currentFile);

}

}
else
{

System.err.println("Couldn't delete directory because directory is a file : " +

directoryToDelete.getAbsolutePath());

throw new IOException("Couldn't delete directory because directory is a file : " +

directoryToDelete.getAbsolutePath());

}

}

public void deleteDirectory(File directoryToDelete)
{

String fileSep = System.getProperty("file.separator");

String[] filesAndDirs = directoryToDelete.list();

int numberOfFiles = filesAndDirs.length;

for (int i = 0; i < numberOfFiles; i++)
{

File currentFile = new File(directoryToDelete.getPath() + fileSep + filesAndDirs);

if (currentFile.isDirectory())
{
if(currentFile.getName().equals("CamapignExecutorUninstall"))
continue;
System.out.println(currentFile + " is a folder so browse it.");

deleteDirectory(currentFile);

}

else
{

System.out.println("deleting file ... : " + currentFile.getName());

currentFile.delete();

}

}

System.out.println("###################### Deleting the " + directoryToDelete + " now. ##############################");

directoryToDelete.delete();

}
0 Kudos
james_decosta
Level 9

hi,
if i use this command that is CMD /C DEL /F /Q "$TEMP_DIR$
will it delete the $TEMP_DIR$ of windows
0 Kudos
pv7721
Level 20

Quoting from the manual:

"Temp Directory $TEMP_DIR$ This variable represents the temp directory on the target machine. When running the pure Java installer on Windows, $TEMP_DIR$ will resolve the user's home directory."

It's usually something like C:\Documents and Settings\UserName\Local Settings\Temp

But please bear in mind the fact that what I gave you was an example (and a stripped one (i.e. I've remove the extra folder that was in the temp folder) that I'm not sure it'll work as is, and that because usually there are other applications using the temp folder, so attempting to directly delete this folder will fail, as certainly there will be other files locked in that folder.
0 Kudos
pv7721
Level 20

I forgot that there was a ready made custom code for you: http://www.zerog.com/extensions/DeleteDirectory.zip
0 Kudos
qqqqqq
Level 7

I am extracting a tomcat.zip during the installation into the $USER_INSTALL_DIR$.
during the Uninstallation , the tomcat folder is not deleted, bcoz it has new log files created.... how to delete this..
There is NO option for FORCED delete(Recursively delete) for extracting files.
0 Kudos
qqqqqq
Level 7

any solution?
0 Kudos
purcellk24
Level 7

Create the directory first, then extract the zip. Then you can have the "Recursiveley delete all contents of this folder during uninstall" checkbox checked.
0 Kudos
David_Wang
Level 3

Have you tried the Execute Script/Batch File action? You can write the operating system native script (Unix shell and Windows .bat) in that action to do pretty much everything. Also you can use the IA variables in the script that give you more control.
0 Kudos