Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

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.
0
Queennie L
Asked:
Queennie L
  • 3
  • 2
1 Solution
 
NVITCommented:
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now