Search code examples
windowsbatch-filefile-rename

Windows Batch : renaming files and replace it filename already exist


I want to rename files in a directory using this command :

for /r %%x in (*.ath) do ren "%%x" *.txt

The problem is if the filename already exists, the file is not replaced. Is there a simple way to delete the old file and then rename the new one ? Thanks


Solution

  • To elaborate on @Ben's comment use

    for /r %%x in (*.ath) do move "%%x" "%%~nx.txt" /y