Need to Create a Task to delete Folder and its files

Hello ,

We have a requirement that we need to create a task that will detect a folder in a drive and then delete the folder and all its files.

Mayank

Hi @Mayank

Hi, for files you can easily use:

delete "C:\x"

For the a folder, you can use: folder delete "C:\x"

You can put an if clause in front of it or put it in the relevance of the task.

This is what error it is giving while running this command.

Q:folder delete “E:\Test”
E: class OperationNotDefined

where did you try to run this?

I use the Q&A, but you need to chose the tab Action:

@steini44

Thanks , i am also using the Fixlet Debugger but i am choosing QnA Tab.
One more query when i am deleting a folder that resides in C drive under program files i am using this command folder delete “C:\Program Files\WPMSUtility” but it is giving me error.

Please let me know

Hi

I don’t know if you can actually execute action script in the QnA tab. Did you try it in the Action tab?

And what error do you have? Otherwise I suggest you open a PMR. Or you can make a custom Fixlet and try it like this (Sometimes the QnA has different results than the console).

Hi

It is working for me in the action tab if i take the action on a folder which is empty(C:\Program Files\Test") but if the Test folder contains some files it is giving us the runtime error.

Please suggest

Hmm, that’s strange:

So this works fine for me…

Do you have sufficient rights on the files you want to delete?

Hi Team,

Try This to delete folder.

waithidden CMD.EXE /C rmdir /Q /S "C:\Program Files\BMC Software\FootPrints Asset Core\Master"
waithidden CMD.EXE /C rmdir /Q /S “C:\Program Files (x86)\BMC Software\FootPrints Asset Core\Master”

REg
Suresh

I’d always suggest using folder delete instead of spawning a thread as it can help make sure the delete happens more robustly.

HI,

Actually the folder that i want to delete contains two exe files that are running continuously and are creating logs files.
Whenever i am running the folder delete command these exe will not get deleted.

Please suggest if there is any way to stop these exe first and then running the folder delete command.

Note: - There is no service running wrt these exe neither any registry entry created for the same.

Well, then it’s logical you can’t delete it. We stop our .exe’s like this (for this example SCCM, when we want to install something else, SCCM sometimes gives a lot of problems :wink: ):

waithidden cmd /C net stop "CcmExec"

First try to stop the .exe in a normal DOS box and then you can try it in BigFix. (just waithidden cmd /c...)

1 Like

@steini44

Can we kill two process at a sametime???

waithidden cmd /C net stop "CcmExec"
waithidden cmd /C net stop "xx"

Just put the new command on a new line. It will execute the second one when the first one is done.

1 Like