Q:

Script for finding specific file (name and type) and copy to new location

I am trouble shooting multiple computers with a software that is doing touch calibration. The software is creating .jpg files that I need to copy and analyze, however different users have installed the software in different locations making it tidius to search for files. Example on a file would be 002CAL000211.jpg.
I would like to create a batch file that can do the following:
Search entire C: drive with (subfolders) and automatically copy specific files to a set directory based on the the following criteria:

Filename contains the name "CAL"
Filetype is ".jpg" 

Preferably I would like the files to be copied to the root of a mounted USB drive.
Any help would be highly appreciated!
Thanks! 

A:

Try this batch script :
@echo off
Title Searching for a specific file (name and type) and copy to USB Drive
Mode con cols=90 lines=10 & color 9E
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=2" %%i in ('wmic logicaldisk where "drivetype=2" ^|find /i ":"') do (Set MyUSB=%%i)
set _drive=%MyUSB%
If defined _drive (
cls
echo.
echo           ---------------------------------------------------------
echo                        Your usb key is connected as !_drive!
echo           ---------------------------------------------------------
echo.
pause
Goto :search
) ELSE (
cls
color 0C
echo.
echo       --------------------------------------------------------------------------
echo       Your usb key is not detected, please check it and re-run again this script
echo       --------------------------------------------------------------------------
echo.
)
pause 
exit

:Search
Cls
echo(
echo       --------------------------------------------------------------------------
echo              Please Wait a while ....... Searching is in progress .........
echo       --------------------------------------------------------------------------
set "LogSearch=%~dp0%~n0.txt"
set Pattern="*CAL*.jpg"
Where /R C:\ "%Pattern%" /F >"%LogSearch%" 2>&1
If "%ErrorLevel%"=="1" (
Cls
echo(
echo       --------------------------------------------------------------------------
@echo                         No file found with this Pattern
echo       --------------------------------------------------------------------------
) else (
    for /f "delims=" %%a in ('Type "%LogSearch%"') do (
        @echo found %%a
        @Copy %%a !_drive!\
    )
)
pause & exit

EDIT : 16/03/2017 @20:00
@echo off
Title Searching for a specific file (name and type) and copy to USB Drive
Mode con cols=90 lines=10 & color 9E
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=2" %%i in ('wmic logicaldisk where "drivetype=2" ^|find /i ":"') do (Set MyUSB=%%i)
set _drive=%MyUSB%
If defined _drive (
cls
echo.
echo           ---------------------------------------------------------
echo                        Your usb key is connected as !_drive!
echo           ---------------------------------------------------------
echo.
pause
Goto :search
) ELSE (
cls
color 0C
echo.
echo       --------------------------------------------------------------------------
echo       Your usb key is not detected, please check it and re-run again this script
echo       --------------------------------------------------------------------------
echo.
)
pause 
exit

:Search
Cls
echo(
echo       --------------------------------------------------------------------------
echo              Please Wait a while ....... Searching is in progress .........
echo       --------------------------------------------------------------------------
set "LogSearch=%~dp0%~n0.txt"
If exist "%LogSearch%" Del "%LogSearch%"
set Pattern="CAL" "ERROR"
For %%P in (%Pattern%) Do (
    Where /R C:\ "*%%~P*.jpg" /F >> "%LogSearch%" 2>&1
    If "%ErrorLevel%"=="1" (
    Cls
    echo(
    echo       --------------------------------------------------------------------------
    echo                         No file(s^) found with this Pattern
    echo       --------------------------------------------------------------------------
    ) else (
        for /f "delims=" %%a in ('Type "%LogSearch%"') do (
            @echo found file %%a
            @Copy /Y %%a !_drive!\
        )
    )
)
pause & exit

