I have a lot of identically named "data.xml" files on my system in different directories.

A basic Windows search easily finds all of these. I would love to be able to do a search on these, find them, and copy them to a directory so there are named data_1.xml etc. etc.

Just the fact that they're all in one directory is what I'm aiming for.

I've tried using Teracopy to do the heavy lifting of copying but it's not renaming the files correctly. Is there any tool out there for something like this?

link|improve this question

43% accept rate
feedback

2 Answers

up vote 1 down vote accepted

Just for completeness, here's a Windows-based solution to run in the CMD shell:

@echo off

set SRC=c:\source
set DST=c:\dest
set FN=0

for /F "usebackq delims=" %%i in (`dir /s /b %SRC%\*.xml`) do call :docopy "%%i"
goto end

:docopy
set /A FN=%FN% + 1
echo copy %1 "%DST%\%~n1_%FN%%~x1"
:end
link|improve this answer
Due to some error on my part or the solution's response, I booted up Windows and gave this a go. While I had to add an actual copy line instead of just the echo line, it worked great! :D – bobber205 Mar 11 '11 at 19:26
feedback

@bobber205

find / -name "*.xml" -exec cp  {} ./ \;

Should do the job.

Store this script say rename.sh and then ./rename.sh

this would rename them

#!/bin/sh
i=1
for j in `ls *.xml`
do
  orig=$j
  echo $orig
  mv $orig orig$i.xml
   i=`expr $i + 1`
done

EDIT

another way to copy is

 find / -name "*.xml" | xargs cp {} /path/to/copy
link|improve this answer
1  
Good answer but while it wasn't overly clear in the original question the OP is using Windows. – John Gardeniers Mar 10 '11 at 21:23
I actually have access to both OS X and Windows for this! :D – bobber205 Mar 10 '11 at 21:43
Thanks so much for your solution! A++++++++ – bobber205 Mar 10 '11 at 21:43
Just now got some time to try this out and the find command replaces the info.xml file with the next one it copies so I only end up with one. :( – bobber205 Mar 11 '11 at 18:38
@bobber205 try this find / -name "*.xml" | xargs cp {} /path/to/copy – Registered User Mar 12 '11 at 20:33
feedback

Your Answer

 
or
required, but never shown

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