Filter Xcopy containing text

January 30, 2012 at 14:25:09
Specs: Windows XP
Filter Xcopy containing text

Is it possible to add a pipe to an Xcopy command to filter the files copied to include only those contains certain text. I can create a file list using the grep command but I was hoping that Xcopy had that capability without using another utility first.

See More: Filter Xcopy containing text

Report •

January 30, 2012 at 20:36:00
I think you can pass wildcards to it...

xcopy "*certain text*"

Do mean to have xcopy inspect the content of each file, or just the content of the file name?

Report •

January 31, 2012 at 06:12:46
I would like for xcopy to inspect the content of each file. I need to copy only files and have certain content to a different folder.

Report •

January 31, 2012 at 21:29:57

To do that with a batch file I think you will have to loop through each line of a file and use findstr to identify the strings you are looking for, and then echo the file names into another list. Then you would use another for loop to xcopy each of the files in that file list to the other directory. Can you give me some example file names and directories?

Report •

Related Solutions

February 1, 2012 at 13:04:37
Thanks, I got it to work using the external file like you suggested. There was other code that populated yesterdays date into %awsdt%. I might change the copy command to xcopy as I refine.

rem ------------------ extract files ---
findstr /m "SearchText" %awsdt%\*.slq > D:\BATCHFILES\EXT\
@echo off
set dst_folder=D:\SLQ
for /f %%i in ( DO copy "%%i" "%dst_folder%"


Report •

February 2, 2012 at 20:34:14
Funny you should mention yesterdays date. I just made this for another post:

REM breaking up date to construct remote file name
set year=%date:~10,4%
set month=%date:~4,2%
set monthday=%date:~7,2%
set /a yesterday=%monthday% - 1

So, you could just use those variables depending on how the file name is structured. If the file is 02012012.txt then the you would set awsdt like this:

set awsdt=%month%%yesterday%%year%.txt

The only problem with this is that it doesn't work on the first of the month since the yesterday variable would be set with 1-1, which equals zero. That could be fixed with some quick calculation of the days in the month though.

Report •

February 7, 2012 at 06:10:24
Thank you...I found yesterdays date which pretty much checks for everything:

@echo off

set yyyy=

set $tok=1-3
for /f "tokens=1 delims=.:/-, " %%u in ('date /t') do set $d1=%%u
if "%$d1:~0,1%" GTR "9" set $tok=2-4
for /f "tokens=%$tok% delims=.:/-, " %%u in ('date /t') do (
for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do (
set %%x=%%u
set %%y=%%v
set %%z=%%w
set $d1=
set $tok=))

if "%yyyy%"=="" set yyyy=%yy%
if /I %yyyy% LSS 100 set /A yyyy=2000 + 1%yyyy% - 100

set CurDate=%mm%/%dd%/%yyyy%
set dayCnt=%1

if "%dayCnt%"=="" set dayCnt=1

REM Substract your days here
set /A dd=1%dd% - 100 - %dayCnt%
set /A mm=1%mm% - 100

if /I %dd% GTR 0 goto DONE
set /A mm=%mm% - 1
if /I %mm% GTR 0 goto ADJUSTDAY
set /A mm=12
set /A yyyy=%yyyy% - 1

if %mm%==1 goto SET31
if %mm%==2 goto LEAPCHK
if %mm%==3 goto SET31
if %mm%==4 goto SET30
if %mm%==5 goto SET31
if %mm%==6 goto SET30
if %mm%==7 goto SET31
if %mm%==8 goto SET31
if %mm%==9 goto SET30
if %mm%==10 goto SET31
if %mm%==11 goto SET30
REM ** Month 12 falls through

set /A dd=31 + %dd%

set /A dd=30 + %dd%

set /A tt=%yyyy% %% 4
if not %tt%==0 goto SET28
set /A tt=%yyyy% %% 100
if not %tt%==0 goto SET29
set /A tt=%yyyy% %% 400
if %tt%==0 goto SET29

set /A dd=28 + %dd%

set /A dd=29 + %dd%

if /I %mm% LSS 10 set mm=0%mm%
if /I %dd% LSS 10 set dd=0%dd%

REM Set IIS and AWS date variables
set IISDT=%yyyy:~2,2%%mm%%dd%
set AWSDT= %mm%%dd%%yyyy%

I found it in:

Thanks you have been a big help. HectorS

Report •

Ask Question