Discussion:
search and copy
(too old to reply)
John
2009-11-04 17:59:56 UTC
Permalink
Is there a tool available to search for keywords in files on a server and
copy them to some location? I am using the search tool to find the text in
the files, but then I find I can't copy all the results because some files
have the same name. I would think a tool that will recreate he path or add
a counter for duplicate filenames. Maybe this would be a tool that I would
have to purchase...
Pegasus [MVP]
2009-11-04 18:57:36 UTC
Permalink
Post by John
Is there a tool available to search for keywords in files on a server and
copy them to some location? I am using the search tool to find the text
in the files, but then I find I can't copy all the results because some
files have the same name. I would think a tool that will recreate he path
or add a counter for duplicate filenames. Maybe this would be a tool
that I would have to purchase...
The following batch file will do this for you:
[01] @echo off
[02] set SourceDir=d:\Some Source Folder
[03] set TargetDir=e:\Some Target Folder
[04] set string=John
[05]
[06] for /F "delims=" %%a in ('dir /s /b "%SourceDir%\*.txt"') do call :Sub
%%a
[07] goto :eof
[08]
[09] :Sub
[10] find /i "%string%" "%*" > nul || goto :eof
[11] echo Copying "%*"
[12] for %%p in ("%*") do set Target=%TargetDir%%%~pp%%~np%%~xp
[13] echo F|xcopy /y "%*" "%Target%" 1>nul

Post again if you need more detailed instructions on its use.
John
2009-11-04 19:35:51 UTC
Permalink
will this search more than just .txt files?
Post by Pegasus [MVP]
Post by John
Is there a tool available to search for keywords in files on a server and
copy them to some location? I am using the search tool to find the text
in the files, but then I find I can't copy all the results because some
files have the same name. I would think a tool that will recreate he
path or add a counter for duplicate filenames. Maybe this would be a
tool that I would have to purchase...
[02] set SourceDir=d:\Some Source Folder
[03] set TargetDir=e:\Some Target Folder
[04] set string=John
[05]
[06] for /F "delims=" %%a in ('dir /s /b "%SourceDir%\*.txt"') do call
:Sub %%a
[07] goto :eof
[08]
[09] :Sub
[10] find /i "%string%" "%*" > nul || goto :eof
[11] echo Copying "%*"
[12] for %%p in ("%*") do set Target=%TargetDir%%%~pp%%~np%%~xp
[13] echo F|xcopy /y "%*" "%Target%" 1>nul
Post again if you need more detailed instructions on its use.
Pegasus [MVP]
2009-11-04 19:42:59 UTC
Permalink
Post by John
will this search more than just .txt files?
Have a look at the code where it says ".txt". You can replace this bit with
your own file spec.

Loading...