|
1 | 1 | #!/usr/bin/python |
2 | | -# -*- coding: utf-8 -*- |
3 | 2 |
|
4 | 3 | # Copyright (c) 2025, Shahar Golshani (@shahargolshani) |
5 | 4 | # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
|
15 | 14 |
|
16 | 15 | description: |
17 | 16 | - This module removes files from a specified directory that match a given pattern. |
18 | | - - The pattern can include wildcards and regular expressions. |
| 17 | + The pattern can include wildcards and regular expressions. |
19 | 18 | - By default, only files in the specified directory are removed (non-recursive). |
20 | | - - Use the O(recursive) option to search and remove files in subdirectories. |
| 19 | + Use the O(recursive) option to search and remove files in subdirectories. |
21 | 20 |
|
22 | 21 | version_added: "12.1.0" |
23 | 22 |
|
24 | 23 | author: |
25 | 24 | - Shahar Golshani (@shahargolshani) |
26 | 25 |
|
| 26 | +extends_documentation_fragment: |
| 27 | + - community.general.attributes |
| 28 | +
|
27 | 29 | attributes: |
28 | 30 | check_mode: |
29 | | - description: Can run in check_mode and return changed status without modifying the target. |
30 | 31 | support: full |
31 | 32 | diff_mode: |
32 | | - description: Will return details on what has changed (or possibly needs changing in check_mode). |
33 | 33 | support: full |
34 | 34 |
|
35 | 35 | options: |
|
43 | 43 | pattern: |
44 | 44 | description: |
45 | 45 | - Pattern to match files for removal. |
46 | | - - Supports wildcards (*, ?, [seq], [!seq]) for glob-style matching. |
| 46 | + - Supports wildcards (V(*), V(?), V([seq]), V([!seq])) for glob-style matching. |
47 | 47 | - Use O(use_regex=true) to interpret this as a regular expression instead. |
48 | 48 | type: str |
49 | 49 | required: true |
|
64 | 64 |
|
65 | 65 | file_type: |
66 | 66 | description: |
67 | | - - Type of files to remove. |
68 | 67 | - V(file) - remove only regular files. |
69 | 68 | - V(link) - remove only symbolic links. |
70 | 69 | - V(any) - remove both files and symbolic links. |
|
123 | 122 | returned: always |
124 | 123 | sample: 2 |
125 | 124 |
|
126 | | -msg: |
127 | | - description: Status message. |
128 | | - type: str |
129 | | - returned: always |
130 | | - sample: "Removed 2 files matching pattern '*.log'" |
131 | | -
|
132 | 125 | path: |
133 | 126 | description: The directory path that was searched. |
134 | 127 | type: str |
@@ -252,7 +245,7 @@ def main(): |
252 | 245 | try: |
253 | 246 | re.compile(pattern) |
254 | 247 | except re.error as e: |
255 | | - module.fail_json(msg=f"Invalid regular expression pattern: {to_native(e)}") |
| 248 | + module.fail_json(msg=f"Invalid regular expression pattern: {e}") |
256 | 249 |
|
257 | 250 | # Find matching files |
258 | 251 | try: |
|
0 commit comments