# win\_command and when condition

**URL:** <https://forum.ansible.com/t/win-command-and-when-condition/33257>\
**Category:** Ansible Project\
**Created:** [June 25, 2020, 6:25am UTC](https://forum.ansible.com/t/win-command-and-when-condition/33257 "2020-06-25T06:25:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shyam.awk](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@shyam.awk](https://forum.ansible.com/u/shyam.awk)\
**Post date:** [June 25, 2020, 6:25am UTC](https://forum.ansible.com/t/win-command-and-when-condition/33257/1 "2020-06-25T06:25:28Z")

</div>

Hi,

Im trying to rename the file using win\_command if the file exists using **when condition,** other wise it won’t execute the command, but it is failing, Can any one suggest.

- name: Rename the file based on condition  
win\_command: cmd.exe /c rename D:\{{item,name}}-filename.json {{item.name}}.filename.json-{{ ansible\_date\_time.date}}  
when: {{item.name}}-filename.json,stat.exists  
loop: {{ variable}}

Thank you,
