Action to empty out a folder

I need a simple folder, can someone help? This is driving me crazy, I just want to empty the contents of C:\Program Files (x86)\HP so that the folder is blank. some of the files are stubborn so the /f switch will be necessary. can someone help me with this, I’m not that good at creating Actions or Fixlets. Thanks in advance.

Sno

You could keep it really simple by doing

folder delete "C:\Program Files (x86)\HP"
folder create "C:\Program Files (x86)\HP"

Failing that you could do

waithidden cmd.exe /c rmdir /s /q "C:\Program Files (x86)\HP"

ScottishGuy, how do you make it quiet and suppress any prompts? If I were to run this in DOS, it would come back asking “are you sure” ?

The ‘/q’ parameter on rmdir makes it quiet.

However the most likely complication preventing you from deleting the folder normally would be that there is a running process from that folder which would keep the folder locked. You won’t be able to delete the folder containing the executable of a running process, regardless of the method you use. You would need to identify the process and kill it before you can delete the folder.

Other options would include updating the PendingFileRenameOperations registry key so that the folder is moved or removed during the next system restart (which is how patch operations replace files that are normally locked by running processes while Windows is running).

It might be possible to ‘move’ the folder rather than delete it, which would cause the expected processes to fail to launch on the next reboot (because the Service, shortcut, or registry link that points to the executable would now have the wrong path).

One more consideration is that by default the client runs in 32-bit mode, so you’d need to have ‘action uses wow64 redirection false’ in the actionscript before trying to launch the ‘wait’ command to delete the folder (otherwise folder redirection will stop you from referencing the Program Files or Program Files (x86) folders directly.

Probably need more details around exactly where your problem is so we can help further.

1 Like

Hi Jason, and thanks as always. I can always place a kill task as the first step in the Action. I’ll give that a try and I’ve noted your other recommendations. Thanks to you and Scottish Guy.

1 Like