views:

122

answers:

3

This

 for /f "tokens=*" %i in ('dir *sonic.exe /s /b') do copy /y "%i" D:\temp\utils\

The question is there a better or shorter way to do it ?

p.s. I know that "tokens=*" could be omitted if the file path does not have spaces ..

Update: I found a shorter ways of finding ( not copying ) from my old cheat sheets:

::START - RUN - cmd.exe
 dir d:\libs\*SubSonic*.dll /s /b>>list.txt&list.txt
:: START - RUN - CMD.EXE 
where /R D:\libs\ *SubSonic*
+1  A: 

You might be able to do this with XCOPY.

This will work but will copy the directory structure too which I don't think is what you want:

XCOPY /S *sonic.exe D:\temp\utils
Dave Webb
Actually it copied only the files containing the string ... XCOPY /S *sonic.exe D:\temp\utils\tmpD:ORM\SubSonic_2.1_Final_Source\src\SubCommander\bin\Debug\sonic.exeD:ORM\SubSonic_2.1_Final_Source\src\SubCommander\obj\Debug\sonic.exe2 File(s) copied
YordanGeorgiev
It will only copy matching files, but if the source file is in a subdirectory called bin then a destination file will be put in a subdirectory called bin too. The FOR loop wouldn't do this, but if you want the subdirectories in the destination then XCOPY is definitely what you want.
Dave Webb
Yep , the folder structure was unneeded and did not exactly answered the question ... I was way to fast to mark the answer without properly testing it ... Anyway thanks for the answers and comments !!!
YordanGeorgiev
You can unmark my answer as accepted. Just click on it again. I'd like to find out the best answer too!
Dave Webb
done ; ) Sorry had to work also a bit ... ; )
YordanGeorgiev
+1  A: 

Something like

dir -r -i *sonic.exe | select-string "tokens=" | % {cp $_ d:\temp\utils}

? [in PS]

Ruben Bartelink
+1 for providing working sample. Thanks. Simple theory without working code about problems discussed here is not very useful ...
YordanGeorgiev
Amusingly, I normally dont post code and send theory (and dont get +1s :D)! (And I didnt test this, though I do similar stuff regularly). If you're interested in PS, there is a new edition of the Payette book on the way to add to your wishlist - it's probably best for devs (there are lots of other good books on PS out there too)
Ruben Bartelink
A: 

Argh ... Hopefully I am wrong. The answer to my knowledge and this answer participation so far ... NO.

Please, comment or hit new answer I will set it as an answer .

YordanGeorgiev