Windows 7 Forums Search
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows 7. The Windows 7 forum also covers news and updates and has an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7 - Help with a little batch file

 
02-07-2011   #1


Windows 7 Ultimate x64
 
 

Help with a little batch file

Hi,

I want to make a bat file and to use informations from a second one, but i don't want to use all the second batch file.

I want to be able to use just a portion of the second one.

First batch:

echo off
cls

del *.tmp

Second batch:

echo off
cls
:1
del *.txt

:2
del *.doc

This is just an example. I just want to edit the first bat file to use only :1 from inside the second one.

Is it possible even ?

And another thing. I just want to add color to a single line in a bat file, not to the whole file. Just to a single word. How is this done ? For an entire file I know, but only for one word I don't.

My System SpecsSystem Spec
02-07-2011   #2


Windows 7 Home Premium x64 OEM --> RTM clean install
 
 


If it were me I would have not 2 but 3 batch files, then only the information needed would be piped to the first batch file. Mop up "del *.doc" in the 3rd batch file using the call caommand. Make sense?

But I'm not very good with batch files!
My System SpecsSystem Spec
02-07-2011   #3


 
 


Sure, pass a parameter to the 2nd batch file from the first one.

batchfile1.bat
echo off
cls
del *.tmp
@rem call batchfile2 passing parameter of 1
batchfile2 1

batchfile2.bat
Rem if no parameters do all
echo off
Rem if 1 do only part 1
if %1==1 goto 1
Rem if 2 do only part 2
if %1==2 goto 2
Rem otherwise do both parts

cls
:1
del *.txt
Rem skip part 2 if parm of 1 received
if %1==1 goto End

:2
del *.doc

:End
My System SpecsSystem Spec
.


02-07-2011   #4


Windows 7 Ultimate x64
 
 


Thanks for your answer. It is very helpful, but after taking the parameter from the second batch, the first batch does not continue the rest of the commands in it. That from above is just an example but I need, after the parameter is runned, the script to continue batchfile1 commands.

I'd like that the first batch file to treat this like one independent command and then skip right on to the other.
My System SpecsSystem Spec
02-07-2011   #5


Windows XP
 
 


See if this is what you are looking for:

First batch file
Code:
@echo off
::Batch File One (bat1.cmd)
cls
dir *.tmp
echo Calling Second Batch File...
pause

call bat2.cmd 1
echo Back to First Batch File...
echo Calling Second Batch File...
pause

call bat2.cmd 2
echo Back to First Batch File...
Second batch file
Code:
@echo off
::Batch File two (bat2.cmd)
cls
if "%1" EQU "" goto :eof
call :%1
goto :eof

:1
Echo Running commands from second batch file passing 1 as parameter...
pause
dir *.txt
goto :eof

:2
Echo Running commands from second batch file passing 2 as parameter...
pause
dir *.doc
goto :eof
The second batch file will do nothing unless a parameter is passed to it on the command line. This can be changed if needed, but should give you the idea of calling one batch file from another, running a specified sub-routine, and then return to the calling batch file.

Scr1ptW1zard
My System SpecsSystem Spec
02-08-2011   #6


Windows 7 Ultimate x64
 
 


Thank you very much, this is exactly what I was looking for. Worked like a charm.

Now, the only problem I face is that of coloring just a line of text and let the rest as default.
My System SpecsSystem Spec
Reply

 Help with a little batch file problems?



Thread Tools



Similar Threads for: Help with a little batch file
Thread Forum
Help required creating batch file to read .csv file General Discussion
batch file open file for program in the startup folder General Discussion
How to create a batch file that will move files based on the file type General Discussion
Batch file for... Customization
Need Help with Batch File General Discussion


All times are GMT -5. The time now is 01:11 AM.



Windows 7 Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows 7" and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30