In Batch, how to copy files within a user specified range

Viewed 38

I have a scenario where I need to copy files from five subdirectories to the directory where the batch file exists. These files are sequential in name in each subdirectory. For example:

FolderA: A001.txt A002.txt A003.txt A004.txt

FolderB B001.txt B002.txt B003.txt B004.txt

FolderC C001.txt C002.txt C003.txt C004.txt

and so on. What I want to be able to do is have a user input where I am able to copy the files from each directory that end in 003 and 004 to a new directory. I have more of the batch that does some data scrubbing from there with the copied files. My problem is getting the files copied based on my number range.

I am able to add a user input to allow me to select all file that end in 003 and copy them, but then I have to run it again to get all files that end in 004. I have close to 25,000 files to search through, and I have completed data mining some. I need to copy them in from a range.

Here is what I have that works to allow me to input and copy a single file set

set fname=
set /P "FileNumber=Please enter File Number: "
if defined FileNumber for /R "\client\A001\M0093" %%I in ("*%FileNumber%*.xml") do (copy /Y "%%I" "\Extraction\Files\"
    set "fname=%%~I"
)
if defined fname (
cls
@echo off
copy "Files\*.txt" Data.txt

Any help would be greatly appreciated.

1 Answers

I am posting from my mobile, so none of this has been tested:

@echo off
set /P "begin=beginning number"
set /P "end=Ending number"
Pushd "client\A001\M0093"
For /l %%i in (%begin%,1,%end%) do for /R %%b in ("*%%i*.xml") do copy /Y "%%~b" "%~dp0"

Also, this assumes the files are copied to the path where the batch-file is located, as you have mentioned.

Related