Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2015-01-08
5
Medium Priority
?
186 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 25

Accepted Solution

by:
NVIT earned 2000 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 25

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn different types of Android Layout and some basics of an Android App.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

715 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