Newbie question (probably!)
Posted: 24 May 2011 14:26
I'm trying to create a batch file to search for files with a word in their title, in both a directory and sub-directory and then copy it to a stated location (this doesn't need to be interactive). I'm a complete batch file newbie, so I have not a single clue where to start. I found a file on the net that searches in the root directory only I cannot seem to figure out what to do next, even after reading some information (thick, I know!). Dir doesn't seem to do much but echo directory structures to me (even with a file name). Can anyone help me sort this out? Here's the code:
Code: Select all
@echo off
cls
:sets
echo you can say "DefaultSearch" for default folder
echo DON'T use ""
set /P SearchIn=What folder shall I search in?:
cls
set DefaultSearch=C:\
set /P FileToSearch=What files to search and copy?:
cls
echo you can say Default for the default folder
echo DON'T use ""
set /P CopyTo=Where shall I copy to?:
set Default="C:\test\"
:begin
cd "%c:\%"
copy *.txt "%c:\test\%"
if not %ErrorLevel% == 0 echo some error, errorlevel is %ErrorLevel% & pause
:end
echo Done.
pause
exit