-1

I want to copy allot of (sound)files, these are all different sounds, but the most of file names are all the same.. and the files are in sub folders that have random characters as their name.

but how do i search and copy all sound files in all random sub folders to one folder? but keep both files that are double and do not overwrite them, like:

Instead of only: Ambient.wav

To this: Ambient(1).wav Ambient(2).wav Ambient(3).wav etc...

I use Windows 7 Ultimate

  • possible duplicate of [How to copy certain files (w/o folder hierarchy), but do not overwrite existing files?](http://stackoverflow.com/questions/17497667/how-to-copy-certain-files-w-o-folder-hierarchy-but-do-not-overwrite-existing) I think that this does almost exactly what you want except maybe minor changes (in the accepted answer instead of copying only the first one you can add a variable and add its numerical value to the file name instead) plus there's `xxcopy` which does exactly that) – Scis Jun 17 '14 at 19:51
  • but it doesn't copy the sound files from all random directories – user3699877 Jun 17 '14 at 20:17

1 Answers1

1
@ECHO OFF
SETLOCAL
SET "sourcedir=U:\sourcedir"
SET "destdir=U:\destdir"
FOR /f "delims=" %%a IN (
 'dir /s /b /a-d "%sourcedir%\*" '
 ) DO (
 IF EXIST "%destdir%\%%~nxa" (
  SET notfound=Y
  FOR /L %%b IN (1,1,999) DO IF DEFINED notfound IF NOT EXIST "%destdir%\%%~na(%%b)%%~xa" (
   ECHO(COPY "%%a" "%destdir%\%%~na(%%b)%%~xa"
   SET "notfound="
  )
  IF DEFINED notfound ECHO(Failed to COPY "%%a"
 ) ELSE (ECHO(COPY "%%a" "%destdir%\%%~nxa"
 )
)

GOTO :EOF

The required COPY commands are merely ECHOed for testing purposes. After you've verified that the commands are correct, change ECHO(COPY to COPY to actually copy the files.

Naturally, the copy could become move if you prefer.

The destination directory should not be a subdirectory of the source.

You could add >nul to the copy to suppress the copied message if desired.

I've used a mask of * for all files. If you only want say .jpgs, then change "%sourcedir%\*" to "%sourcedir%\*.jpg"

Magoo
  • 77,302
  • 8
  • 62
  • 84