Solved

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

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

Accepted Solution

by:
NVIT earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Excellent Job!
0
 
LVL 23

Expert Comment

by:NVIT
Comment Utility
Glad to help you. Maraming salamat po for the points.
0
 

Author Comment

by:Queennie L
Comment Utility
Maraming Salamat sa pagsagot.

Have a great day!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumDigits  challenge 7 60
pairs challenge 5 44
Turning python script into an applet 12 32
Path to Python 9 36
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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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). …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now