Computing.Net > Forums > Disk Operating System > Copy a File based on Find results

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Copy a File based on Find results

Reply to Message Icon

Name: lucour
Date: October 23, 2002 at 11:56:33 Pacific
OS: Windows XP
CPU/Ram: AMD Athlon 256 mb DDR
Comment:

Hi,

I have a directory called C:\Bankfiles. Each day this directory is populated with new .txt files. The file names are never the same since these are validation reports, and thus generated by the bank. One day a file name could be jgh10042.txt and the next day it could be ght44589.txt. Here is what I want to do. Search inside all of these .txt files in C:\Bankfiles for customer number "TDCUST022" and whichever file contains this search string, copy it to a folder called C:\CustFound. So far I have tried the DOS Find command:

Find /c "TDCUST022" C:\BankFiles

This produces the following:


D:\BatTest>find /c "TDMAR10202" D:\Battest\*.txt


---------- C:\BankFiles\JKH47226.TXT: 0

---------- C:\BankFiles\JOH43285.TXT: 0

---------- C:\BankFiles\JOH55272.TXT: 1

So as you can see, the last file (JOH55272.TXT) is the file I want to copy to C:\CustFound. How do I do this ?




Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: October 23, 2002 at 14:52:05 Pacific
Reply:

This should do it:

for %%? in (C:\Bankfiles\*.txt) do (
    FIND "TDMAR10202" < %%~fs? > nul
    if not errorlevel=1 (
        copy %%~fs? C:\CustFound
        goto fend
    )
)
:fend

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0
Reply to Message Icon

Related Posts

See More


The sblaster command Dos Client AutoConnect



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Copy a File based on Find results

Trying to purge files based on Date www.computing.net/answers/dos/trying-to-purge-files-based-on-date/13804.html

Removing files based on creation date www.computing.net/answers/dos/removing-files-based-on-creation-date/10389.html

Copying a File to Multiple Disks www.computing.net/answers/dos/copying-a-file-to-multiple-disks/4355.html