Solved Batch file to copy files

December 9, 2015 at 19:36:25
Specs: Windows 7

I have about 20000 image and video files spread across several old computers and portable HDD's that I would like to consolidate on one new big HDD.

I have a basic knowledge of COPY, XCOPY and ROBOCOPY but have been tearing my hair out tryingto find a solution to what i thought was a simple problem !

I need to create a batch file that will find ALL .JPG and .MP4 files on a computer and copy them to the new HDD. I need to find hidden files, and I need to rename any duplicates.

I would love to use a batchfile as Id like it to be portable.

Any suggestions would be most appreciated !


See More: Batch file to copy files

Report •

December 9, 2015 at 21:41:52
✔ Best Answer
First, I would build a list to a text file. This gives you a record:
cd \
dir /s /b /a /o-d *.jpg>list
dir /s /b /a /o-d *.mp4 >>list

This records the full pathnames so the directory structure is recorded. That can be important.
Next, run a for /F on the file:

for /F "tokens=*" %%a in (list) do (
if not exist "Z:%%~nxa" (
copy "%%a" Z:
) else (
call :renam "%%~nxa"
goto :eof

set junk=%time::="
set junk=%junk:.=@"
set junk=%junk: ="
copy %1 Z:%~n1%junk%%~x1
::--------- not fully tested - might be some "glubs" to work out.
The renaming is only my approximation. Use your own methods and formatting for generated filenames.

message edited by nbrane

Report •

December 13, 2015 at 17:43:09
thankyou for your help !

Its great to get others opinions as Id never considered doing it this way.

Ill give it a run and see how it goes !

Thanks again

Report •

Related Solutions

Ask Question