Search&copy file containing specifc text to a certain path

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Bowlardo
Posts: 15
Joined: 28 Jun 2012 07:28

Search&copy file containing specifc text to a certain path

#1 Post by Bowlardo » 28 Jun 2012 08:38

Search&copy file containing specifc text to a certain path (on a daily basis)
I am searching the sub folders of the following path P:\Gent\IntIn\#2012\06\28
(P:\Gent\IntIn\#2012\06\>findstr /s /m "SDT=:034273901" *.* )
I am using the command findstr /s /m "SDT=:034273901" *.*
and it returns the name of the file (IN_file__6789101.txt)
How do I copy that file and it's contents to the P:\Gent\IntIn\#2012\06\28

I also tried
findstr /s /p "sdt=:03427391" *.* > fileP.txt
the fileP.txt file has exactly what I want except that the file name is populated in the first few postions of the FileP.txt.
The files name will not always be the same lenght so I am not sure if removing text from the strart of the file is an option

Any suggestion would be greatly appreciated :D

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Search&copy file containing specifc text to a certain pa

#2 Post by foxidrive » 28 Jun 2012 09:11

This should work (untested)

Code: Select all

@echo off
pushd "P:\Gent\IntIn\#2012\06\28"
for /f "delims=" %%a in ('findstr /s /m "SDT=:034273901" *.*') do (
echo copying %%a
copy /b "%%a" .
)
popd

Bowlardo
Posts: 15
Joined: 28 Jun 2012 07:28

Re: Search&copy file containing specifc text to a certain pa

#3 Post by Bowlardo » 05 Jul 2012 10:08

Thanks Foxidrive. That worked perfectly.

Much appreciated :D

Post Reply