list the all the file in directory and redirect the only file name to property file

Hi,

wanted to list the files in a directory and copy the only file name into property file,
using by win_shell:

  • name:list the files
    win_shell: ‘ls {{directory}} > {{directory}}/manifest.prob’
    register: dir_out

  • debug: var={{item}}
    with_items: dir_out.stdout_lines

out put as

Mode LastWriteTime Length Name


-a---- 9/9/2019 9:05 AM 7289 Database_0.0.100.zip
-a---- 9/9/2019 9:03 AM 18447 EMC_ECS-package_0.0.100.zip
-a---- 9/17/2019 1:02 PM 0 file.txt
-a---- 9/9/2019 9:05 AM 7434 hotfix-DDMInfra.zip
-a---- 9/9/2019 9:03 AM 15631 hotfix-IIS.zip
-a---- 9/9/2019 9:05 AM 16808 hotfix-QCIM1H126382-v3.zip
I don’t want other information, How list only file names?

Hi uppara

On Linux system we have a parameter -1 to list only names of files.

Walber

but I’m working in Windows;
I used Command module as

  • name: list the files

win_command: dir /b /a-d

fatal: [172.31.17.108]: FAILED! => {
“changed”: false,
“cmd”: “dir /b /a-d”,
“msg”: “Exception calling "SearchPath" with "1" argument(s): "Could not find file ‘dir.exe’."”,
“rc”: 2
}

got above error

Use the win_find module