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

**URL:** <https://forum.ansible.com/t/list-the-all-the-file-in-directory-and-redirect-the-only-file-name-to-property-file/31298>\
**Category:** Ansible Project\
**Created:** [September 17, 2019, 1:12pm UTC](https://forum.ansible.com/t/list-the-all-the-file-in-directory-and-redirect-the-only-file-name-to-property-file/31298 "2019-09-17T13:12:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Uppara\_venkat](https://avatars.discourse-cdn.com/v4/letter/u/6a8cbe/32.png) [@Uppara\_venkat](https://forum.ansible.com/u/Uppara_venkat)\
**Post date:** [September 17, 2019, 1:12pm UTC](https://forum.ansible.com/t/list-the-all-the-file-in-directory-and-redirect-the-only-file-name-to-property-file/31298/1 "2019-09-17T13:12:10Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Walber\_Santos](https://avatars.discourse-cdn.com/v4/letter/w/8c91f0/32.png) [@Walber\_Santos](https://forum.ansible.com/u/Walber_Santos)\
**Post date:** [September 17, 2019, 3:13pm UTC](https://forum.ansible.com/t/list-the-all-the-file-in-directory-and-redirect-the-only-file-name-to-property-file/31298/2 "2019-09-17T15:13:17Z")

</div>

Hi uppara

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

Walber

---

<div class="post-metadata">

**Author:** ![Uppara\_venkat](https://avatars.discourse-cdn.com/v4/letter/u/6a8cbe/32.png) [@Uppara\_venkat](https://forum.ansible.com/u/Uppara_venkat)\
**Post date:** [September 17, 2019, 3:35pm UTC](https://forum.ansible.com/t/list-the-all-the-file-in-directory-and-redirect-the-only-file-name-to-property-file/31298/3 "2019-09-17T15:35:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [September 17, 2019, 5:04pm UTC](https://forum.ansible.com/t/list-the-all-the-file-in-directory-and-redirect-the-only-file-name-to-property-file/31298/4 "2019-09-17T17:04:43Z")

</div>

Use the win\_find module
