How can I search and copy files using a .bat file?

5,321

This batch script will help you achieve what you're after

@ECHO OFF
SET /P drive="Enter the drive letter"
FOR /R "%drive%:\" %%G IN (*.txt) DO (
ECHO COPY %%G W:\RestorePoint\%%~nG
)

I'm assuming in this script that the restore directory is "W:\RestorePoint" which is a directory that needs to be created prior to running the script.

Share:
5,321

Related videos on Youtube

Anderson Oliveira
Author by

Anderson Oliveira

Updated on September 18, 2022

Comments

  • Anderson Oliveira
    Anderson Oliveira over 1 year

    I would like to search for all .txt files from a computer drive and copy them to a specific folder using a batch file.

    • fixer1234
      fixer1234 over 8 years
      You're talking about recursing through all directories on the drive and copying all .txt files to a single folder on another drive?
    • Anderson Oliveira
      Anderson Oliveira over 8 years
      Yes, that's what I want.
  • Dhiwakar Ravikumar
    Dhiwakar Ravikumar over 8 years
    If you felt my answer was helpful please mark it and upvote it :) Thank you