0

How do I give a command on Command Prompt in Windows which executes on all the files in the directory as well as it's all subdirectories?

For example: ren *.txt *. - this command removes the extension .txt from all the files in the current directory but not its subdirectories. I want it to be executed on all the files in all its subdirectories too. How do I do this?

  • Does this answer your question? [Batch script to execute some commands in each sub-folder](https://stackoverflow.com/questions/33276921/batch-script-to-execute-some-commands-in-each-sub-folder) – Svirin Sep 15 '20 at 11:51
  • `for /d %i in (D:\*) do ( cd "%i" & ren *.txt*. )` I tried using this command as mentioned in the link, it just does it on the immediate subdirectories but not on the subsubdirectories. I want it to be executed on all files under the directory. – Ayush Chaurasia Sep 15 '20 at 12:02
  • 2
    Try `for /r "." %i in (*.txt)do @ren "%i" "%~ni"` instead. Where the `/R` option designates the location to root the command from. In the given example, I've used `"."` to base it from the current directory, so if you wanted to root it specifically from the `D:` drive, you'd replace `"."` with `"D:"` To find out more about the available options, please open a Command Prompt window, typre `for /?`, press the `[ENTER]` key, and read the information presented. – Compo Sep 15 '20 at 12:32

0 Answers0