Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.

Try this:
::== copylogs.bat
:mainfor %%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

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.

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

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?
LeoLeonard B.

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.

![]() |
![]() |
![]() |

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