Create Windows Batch file to search for parts of word/words in a text files

What I want is to create a windows batch file to find in a directory any strings in text files then if match then copy and move to another folder.

This batch file script is what I have so far but it moves all the text files with Weekly words:

@ECHO off
for %%a in ( "C:\Users\Scripts\*Weekly.*" ) do (
    copy "%%~a" "C:\Users\Scripts"
    move "%%~a" "C:\Users\ScriptsTo"
)
pause

Open in new window



Examples:

These are my text files in the Source folder:
011111CurWeekly.010815.txt
022222Weekly010815.txt
033333Weekly010815.txt
044444Weekly010815.txt

All I need is to copy and move to Destination folder is with strings contains ONLY "Weekly":
022222Weekly010815.txt
033333Weekly010815.txt
044444Weekly010815.txt

I don't need this file to move:
011111CurWeekly.010815.txt


Is this possible?

Thank you for your help.
Queennie LAsked:
Who is Participating?
 
NVITConnect With a Mentor Commented:
Your COPY command doesn't make sense. It's copying to same folder. I haven't checked if it will throw an error.

Anyway, how about:

@ECHO off
for %%a in ( "C:\Users\Scripts\??????Weekly??????.*" ) do (
    copy "%%~a" "C:\Users\Scripts"
    move "%%~a" "C:\Users\ScriptsTo"
)
pause

Open in new window

0
 
Queennie LAuthor Commented:
Ignore the copy, I made a mistake.

This batch file works like a charm.

Thank you very much.
0
 
Queennie LAuthor Commented:
Excellent Job!
0
 
NVITCommented:
Glad to help you. Maraming salamat po for the points.
0
 
Queennie LAuthor Commented:
Maraming Salamat sa pagsagot.

Have a great day!
0
All Courses

From novice to tech pro — start learning today.