Computing.Net > Forums > Windows XP > Batch File: Match & Copy

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch File: Match & Copy

Reply to Message Icon

Name: leonardbd
Date: January 18, 2006 at 20:49:44 Pacific
OS: WinXP
CPU/Ram: 512/P4
Comment:

I need a couple of Dos command to make a batch file which will find a specific word from few txt LOG file like backup01.txt, backup02.txt and if Match the word it will copy that file to a new destination.
Suppose I have 20 LOG file created by NTBACKUP
: backup01.txt, backup02.txt...backup20.txt
Every LOG file contaies remote Source path like "\\PC01\Documents & Settings", "\\PC02\Documents & Settings\",...... "\\PC20\Documents & Settings\"
I need a batch file which will search the a given value like "\\PC19\Documents & Settings" from every LOG file and if match it will copy the LOG file (containing the given value) to a new Folder such as C:\PC19\
Is that possible?
Please help.
Leonard


Leonard B.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: January 19, 2006 at 04:07:42 Pacific
Reply:

Try this:

::== copylogs.bat
:main

for %%L in (backup*.txt) do call :sub1 %%L
goto :eof

:sub1

find /i "Documents & Settings" < %1 > ##
set /p ##=<##
if not exist "%##:~2,4%" md "%##:~2,4%"
copy %1 "%##:~2,4%" > nul
goto :eof
:: DONE


If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: leonardbd
Date: January 19, 2006 at 04:50:38 Pacific
Reply:

Oh thanks, but if you tell me which syntex doing what action then it will be better for me to find out any problem when I try. I have already tried but couldnt get the my actual result.
Please help me to understand the total syntex.

Thanks
Leo


Leonard B.


0

Response Number 3
Name: Mechanix2Go
Date: January 19, 2006 at 05:08:28 Pacific
Reply:

Hi Leo,

Ignoring the blank lines so that :main is #1 and number 2 starts with for:

line 2 looks for files named backup*.txt and CALLS :sub1 and passes it the name of the file.

line 5 is the first line of :sub1. It gets the filename as %1 and FINDs the string "Documents & Settings" and puts what it found into a file called ##.

line 6 sets a variable named ## to the line contained in the file ##.

in line 7 we want to create a directory named with the form PCxy, so this syntax:

"%##:~2,4%"

tells it to use what's in the variable ## but SKIP the first two chars [which are \\] and use the next four.

line 8 copies the file to the directory we made.

line 9 ends :sub1

line 3 ends the batch

Does that make sense?


If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: leonardbd
Date: January 23, 2006 at 19:03:14 Pacific
Reply:

Thank you. But I think I made some mistake to apply this to my task. Let me give you the real scenario.

I have 25 LOG file in C:\LOG\ folder. All LOG file contains an UNIC PC ID like, in LOG file 'backup01.log' contain 'PC4002', 'backup02.log' contain 'PC4003' and so on till backup25.log.
Now I want to copy the LOG file which contain 'PC4003' to 'c:\PC4003\' with a batch command and with another batch I want to copy the LOG file which contain 'PC4002' to 'c:\PC4002\' folder.
What will be the actual commands for this?


Leo

Leonard B.


0

Response Number 5
Name: leonardbd
Date: February 5, 2006 at 21:14:40 Pacific
Reply:

Can anyone help me with following...

In BKS file of NTBACKUP I can mention which folder or file to be backed up. But
can I exclude any file or folder from .bks file ? if it possible please show me the commant syntex.

Leo

Leonard B.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Windows XP Forum Home


Sponsored links

Ads by Google


Results for: Batch File: Match & Copy

Batch File to search, copy , rename www.computing.net/answers/windows-xp/batch-file-to-search-copy-rename/154130.html

simple batch file www.computing.net/answers/windows-xp/simple-batch-file/149160.html

DOS Batch file command www.computing.net/answers/windows-xp/dos-batch-file-command/145299.html