| 1. |
Solve : Batch - Copy files with a same filename within a folder structure? |
|
Answer» Hey folks!
There are never two files with same name in the same folder.Are you still interested in this? I happen to be WORKING on a project which is related and might help you out. Pleas give more details on what you are trying to achieve. What type of files, etc...? [emailprotected]If understand this correctly, you have duplicate file names across a directory tree but now you want them in a single directory where duplicate file names can be a real problem. One solution would be to use XCOPY as a helper utility (use the /s switch to hunt down all the files in the tree, but also use the /l switch to not actually copy anything. Th end result will be a list of files that would have been copied which you can use in combination with an existence test and the plain old COPY utility. Along the way you can build a sequence number to add to the file name to prevent duplicates. A bit unconventional perhaps, but sound logic. Code: [Select]@echo off setlocal set source=i:\myFiles set target=c:\temp for /f "tokens=*" %%i in ('xcopy /s /e /l %source%\* %target%') do ( if exist %target%\%%~ni%%~xi (call :sequence %%i) else (copy "%%i" "%target%\%%~ni%%~xi" 1>nul 2>nul) ) goto :eof :sequence for /l %%x in (1,1,25) do ( if not exist "%target%\%~n1_%%x%~x1" ( copy "%%i" "%target%\%~n1_%%x%~x1" 1>nul 2>nul goto :eof ) ) goto :eof Be sure to set the source and target variables to valid values for your machine. The current script is set for a possible 25 duplicates for any single file name. Change as necessary. Good luck. |
|