Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8261031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:15:40+00:00 2026-06-08T03:15:40+00:00

I have a master file ( File1.txt ) where some names are maintained in

  • 0

I have a master file (File1.txt) where some names are maintained in the contents. I have to find all the files which has those kind of names (wild cards) in a folder and move them to a different folder using batch file program.

Eg : File1.txt has contents

  abcd
  efgh

now in the folder say c:\temp\Source i have files like

12abcd34.asc
56efgh78.asc
testing.asc

I have to move only those 2 files to a folder say c:\temp\Target.

Here’s my code, but it gives error saying i*.* is unexpected at this time. Can you please help .

@Echo Off
title Test move files
set dir1=C:\temp\Source
dir %dir1%
Echo Directory Changed
FOR /f "eol=; delims=, " %i in (file1.txt) do move /y "*%i*.*" Target
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:15:41+00:00Added an answer on June 8, 2026 at 3:15 am

    Here you go….

    This is what the directory structure is when I start…

    C:\Temp>tree /f
    Folder PATH listing for volume OS
    Volume serial number is XXXX-XXXX
    C:.
    │   file1.txt
    │   run.bat
    │
    ├───Source
    │       12abcd34.asc
    │       56efgh78.asc
    │       testing.asc
    │
    └───Target
    

    This is the run.bat that I will run later .. includes the bug fixes…

    C:\Temp>copy run.bat con
    @Echo Off
    
    title Test move files
    
    set dir1=Source
    
    dir %dir1%
    
    Echo Directory Changed
    
    FOR /f "eol=; delims=, " %%i in (file1.txt) do move /y "%dir1%\*%%i*.*" Target
            1 file(s) copied.
    

    Now I run the batch file …

    C:\Temp>run.bat
     Volume in drive C is OS
     Volume Serial Number is XXXX-XXXX
    
     Directory of C:\Temp
    
    19/07/2012  00:03    <DIR>          .
    19/07/2012  00:03    <DIR>          ..
    18/07/2012  23:59                 0 12abcd34.asc
    18/07/2012  23:59                 0 56efgh78.asc
    18/07/2012  23:59                 0 testing.asc
                   3 File(s)              0 bytes
                   2 Dir(s)  41,653,194,752 bytes free
    Directory Changed
    C:\Temp\Source\12abcd34.asc
            1 file(s) moved.
    C:\Temp\Source\56efgh78.asc
            1 file(s) moved.
    

    Now this is the final directory structure … so you can see that it is working …

    C:\Temp>tree /f
    Folder PATH listing for volume OS
    Volume serial number is XXXX-XXXX
    C:.
    │   file1.txt
    │   run.bat
    │
    ├───Source
    │       testing.asc
    │
    └───Target
            12abcd34.asc
            56efgh78.asc
    

    Here is the for loop you need…

    FOR /f "eol=; delims=, " %%i in (file1.txt) do move /y "%dir1%\*%%i*.*" Target
    

    Changes:

    [1] within FOR you use %%i not %i.
    [2] You need this format:
    
    %dir1%  <-- Where
    \       <-- path delimiter
    *       <-- starts with anything
    %%i     <-- contains what you want to search
    *.*     <-- ends with anything
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two files: master/newsletter1/file.html master/newsletter2/file.html newsletter1/file.html has a lot of new changes that
I have a master build file which is calling other build.xml files of different
I have a Master Page which has an associated css file. On one of
I have a directory which has say 10 .txt files. Open the directory using:
I have a file in my master git branch called 'Readme.' The file has
I have a requirement. I have some files in a folder among which some
I have a list of text files file1.txt, file2.txt, file3.txt .. filen.txt that I
I have two files which have a list of sites in them. The master
I have merged master into my bugXY branch, and needed to merge a file.
I have a dependencies section in my master build.gradle file subprojects { dependencies {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.