Solved

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

Posted on 2015-01-08
5
182 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can i compile this github project?? 2 85
detecting  the added row index in a datagridview 3 71
Query Syntax 17 36
What does != "" mean in programming 8 34
This is an explanation of a simple data model to help parse a JSON feed
When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
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…

810 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