Morti
Morti

Reputation: 717

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

Upvotes: 0

Views: 6225

Answers (1)

Bali C
Bali C

Reputation: 31251

To elaborate on @Ben's comment use

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

Upvotes: 2

Related Questions