Skip to content

Commit

Permalink
[Windows] Get files under recursive directory (#456)
Browse files Browse the repository at this point in the history
Signed-off-by: Yanan Shen <[email protected]>
  • Loading branch information
123lzxm authored Apr 13, 2023
1 parent 1cd0d11 commit 624f386
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
18 changes: 12 additions & 6 deletions windows/utils/win_get_file_folder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,25 @@
# win_get_src_path: the source path
# win_get_dst_path: the destination path
#
# Check if the specified path is a directory
- include_tasks: win_is_folder.yml
- name: "Set the fact of file path"
ansible.builtin.set_fact:
win_dst_path: "{{ win_get_dst_path }}"

- name: "Check if the path {{ win_get_src_path }} is a directory"
include_tasks: win_is_folder.yml
vars:
win_is_folder_path: "{{ win_get_src_path }}"

- include_tasks: win_get_file.yml
- name: "Get file from guest OS"
include_tasks: win_get_file.yml
vars:
win_get_file_src_path: "{{ win_get_src_path }}"
win_get_file_dst_path: "{{ win_get_dst_path }}"
win_get_file_dst_path: "{{ win_dst_path }}"
when: not win_is_folder_result

- include_tasks: win_get_folder.yml
- name: "Get the files in sub folders"
include_tasks: win_get_folder.yml
vars:
win_get_folder_src_path: "{{ win_get_src_path }}"
win_get_folder_dst_path: "{{ win_get_dst_path }}"
win_get_folder_dst_path: "{{ win_dst_path }}"
when: win_is_folder_result
31 changes: 21 additions & 10 deletions windows/utils/win_get_folder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,43 @@
# win_get_folder_src_path: the source folder in Windows guest OS
# win_get_folder_dst_path: the destination path in local machine
#
- ansible.builtin.debug:
- name: "Display the source folder path"
ansible.builtin.debug:
msg: "Specified source folder path is: {{ win_get_folder_src_path }}"

# Check specified folder exists in guest OS
- include_tasks: win_check_file_exist.yml

- name: "Check if the folder {{ win_get_folder_src_path }} exists in guest OS"
include_tasks: win_check_file_exist.yml
vars:
win_check_file_exist_file: "{{ win_get_folder_src_path }}"

- block:
- include_tasks: win_get_sub_files_folders.yml
- name: "Set the result of file existing"
ansible.builtin.set_fact:
win_file_exist: "{{ win_check_file_exist_result }}"

- name: "Get files from guest OS"
block:
- name: "Get files and sub folders under directory {{ win_get_folder_src_path }}"
include_tasks: win_get_sub_files_folders.yml
vars:
win_get_files_folders_folder: "{{ win_get_folder_src_path }}"

- include_tasks: win_get_file_folder.yml
- name: "Fetch files from guest OS"
include_tasks: win_get_file_folder.yml
vars:
win_get_dst_path: "{{ win_get_folder_dst_path }}"
with_items: "{{ win_get_files_folders_list }}"
loop_control:
loop_var: win_get_src_path
when: win_get_files_folders_list | length | int != 0

- ansible.builtin.debug:
- name: "Display message for empty file list"
ansible.builtin.debug:
msg: "Specified folder '{{ win_get_folder_src_path }}' is empty: {{ win_get_files_folders_list }}"
when: win_get_files_folders_list | length | int == 0
when: win_check_file_exist_result
when: win_file_exist

- ansible.builtin.debug:
- name: "Display the message for no file existing"
ansible.builtin.debug:
msg: "Folder not exist in guest OS: {{ win_get_folder_src_path }}, skip getting files"
when: not win_check_file_exist_result
when: not win_file_exist

0 comments on commit 624f386

Please sign in to comment.