Solved

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

Posted on 2015-01-08
5
183 Views
Last Modified: 2015-01-09
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
Comment
Question by:Queennie L
  • 3
  • 2
5 Comments
 
LVL 24

Accepted Solution

by:
NVIT earned 500 total points
ID: 40538891
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
 

Author Comment

by:Queennie L
ID: 40539003
Ignore the copy, I made a mistake.

This batch file works like a charm.

Thank you very much.
0
 

Author Closing Comment

by:Queennie L
ID: 40539004
Excellent Job!
0
 
LVL 24

Expert Comment

by:NVIT
ID: 40539098
Glad to help you. Maraming salamat po for the points.
0
 

Author Comment

by:Queennie L
ID: 40540253
Maraming Salamat sa pagsagot.

Have a great day!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# application error "Parameter Is Not Valid". 3 113
Advice in Xamarin 21 96
VB.net and sql server 4 45
Selenium docs api java index 3 48
This is an explanation of a simple data model to help parse a JSON feed
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question