Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

dir1\f
dir2\f
dir3\f
...

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

dir1-f
dir2-f
dir3-f

Can I do this using a Windows batch file?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

From the command line:

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

Or

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

share|improve this answer

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.

share|improve this answer
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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