My source folder contains directories containing files like this (each file has the same name):


I would like to copy all files named f to another directory, renamed as follows:


Can I do this using a Windows batch file?


From the command line:

for /d %F in (*) do @copy /y "%F\f" "\someFolder\%F-f" 2>nul


for /d %F in (*) do @if exist "%F\f" copy /y "%F\f" "\someFolder\%F-f"

Double up the percents if used in a batch file


You can do this in a batch file, open up a command prompt and type for /?, there are numerous examples on google to do this type of thing.

  • 1
    -1 if/when you have the rep to comment, then that may have been worthy of a comment(though i doubt it was even worthy of that), but certainly not worthy of an answer. The comment might've gone like -I don't know, or I don't know off hand off hand-, followed by but try for /?. But I wouldn't even have done that comment because enough people know it involves for and can answer. a comment would've been okish.. but for /? is totally unworthy of being an answer. – barlop Sep 16 '13 at 11:46
  • I see, well i can provide an example then. I have read others flaming for providing the batch command to do it. – Clint Priest Sep 16 '13 at 16:47
  • be interesting to see the link to that "flaming for providing the batch command". one of the very positive things about how this is designed, is it's a database of questions and answers, (and even any forum should be actually)..it's not so much about helping a person, but about answering the question they ask(and if they ask a good question it helps them - if they don't then one may comment suggesting a different question or framework for an alternative solution). Also re flaming, like many people saying the same criticism, votes are good there in the design so more compact. – barlop Sep 17 '13 at 14:15
  • That said. On that last point re flaming, don't let the fact that your answer is only at -1, lead you to think it wasn't such a bad answer. It was. It is rare for people to pile on downvotes as a sort of flame. (though if they did then notice it is a lot neater than traditional flaming). – barlop Sep 17 '13 at 14:20
  • Looks like the flame comment has since been removed but it was on this post: superuser.com/questions/645730/… – Clint Priest Sep 17 '13 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.