diff --git a/README.md b/README.md index fe00c35..9daa55e 100644 --- a/README.md +++ b/README.md @@ -837,18 +837,20 @@ For best results, the file path parameter should be an absolute path to a PARAMETER | REQUIRED | DESCRIPTION | TYPE | CONTAINS --------- | -------- | ----------- | ---- | -------- **ip_hostname** | optional | IP/Hostname | string | `ip` `host name` -**file_path** | required | Path to file | string | `file path` +**file_path** | required | Path to file / directory | string | `file path` **force** | optional | Use the force flag for delete | boolean | +**recurse** | optional | Use the recurse flag to delete directory content recursively | boolean | #### Action Output DATA PATH | TYPE | CONTAINS | EXAMPLE VALUES --------- | ---- | -------- | -------------- action_result.parameter.file_path | string | `file path` | C:\\Windows\\System32\\notepad.exe action_result.parameter.force | boolean | | True False +action_result.parameter.recurse | boolean | | True False action_result.parameter.ip_hostname | string | `ip` `host name` | 8.8.8.8 8.8.8.8\\testphantom.local action_result.data | string | | action_result.status | string | | success failed action_result.message | string | | Successfully deleted files action_result.summary | string | | summary.total_objects | numeric | | 1 -summary.total_objects_successful | numeric | | 1 \ No newline at end of file +summary.total_objects_successful | numeric | | 1 diff --git a/winrm_connector.py b/winrm_connector.py index e1b99a5..f14d9f4 100644 --- a/winrm_connector.py +++ b/winrm_connector.py @@ -995,11 +995,13 @@ def _handle_delete_file(self, param): return action_result.get_status() file_path = self._handle_py_ver_compat_for_input_str(param['file_path']) - force_delete = '-Force ' if param.get('force') else '' + recurse_delete = ' -Recurse' if param.get('recurse') else '' + force_delete = ' -Force' if param.get('force') else '' - ps_script = "& del {0}{1}".format( - force_delete, - self._sanitize_string(file_path) + ps_script = "Remove-Item -Path {0}{1}{2}".format( + self._sanitize_string(file_path), + recurse_delete, + force_delete ) ret_val = self._run_ps(action_result, ps_script, parse_callback=pc.check_exit_no_data2)