Help with a little batch file

masca90020

New member
Local time
1:38 AM
Messages
24
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 Computer My Computer

At a glance

Windows 7 Ultimate x64
OS
Windows 7 Ultimate x64
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 Computer My Computer

At a glance

Windows 7 Home Premium x64 OEM --> RTM clean ...Intel T44004Gb? - Mobile Intel(R) 4 Series Express Chipset ...
Computer Manufacturer/Model Number
Toshiba Satellite L500
OS
Windows 7 Home Premium x64 OEM --> RTM clean install
CPU
Intel T4400
Motherboard
? - laptop inbuilt ?
Memory
4Gb
Graphics Card(s)
? - Mobile Intel(R) 4 Series Express Chipset Family ?
Sound Card
Realtek
Monitor(s) Displays
? + extended to a 42" LG55PC plasma tele!
Screen Resolution
1366 * 768
Hard Drives
320Gb 5500rpm
PSU
?
Case
?
Cooling
?
Internet Speed
3Meg, when it works.
Other Info
A LOWLY LAPTOP!
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 Computer My Computer

At a glance

Windows 10 Pro X64Intel Quad Core i7-4770 @ 3.4Ghz16.0GB PC3-12800 DDR3 SDRAM 1600 MHzIntel Integrated HD Graphics
Computer type
PC/Desktop
Computer Manufacturer/Model Number
Lenovo IdeaCenter 450
OS
Windows 10 Pro X64
CPU
Intel Quad Core i7-4770 @ 3.4Ghz
Memory
16.0GB PC3-12800 DDR3 SDRAM 1600 MHz
Graphics Card(s)
Intel Integrated HD Graphics
Sound Card
Realtek HD Audio
Monitor(s) Displays
HP 22" LCD
Screen Resolution
1680 x 1050
Hard Drives
250GB Samsung EVO SATA-3 SSD
2TB Seagate ST2000DM001 SATA-2
1.5TB Seagate ST3150041AS SATA
Keyboard
Dell USB
Mouse
Lenovo USB
Internet Speed
Cable via Road Runner 3MB Upload, 30MB Download
Antivirus
Windows Defender, MBAM Pro, MBAE
Browser
Seamonkey
Other Info
UEFI/GPT
PLDS DVD-RW DH16AERSH
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 Computer My Computer

At a glance

Windows 7 Ultimate x64
OS
Windows 7 Ultimate x64
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 Computer My Computer

At a glance

Windows XP
OS
Windows XP
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 Computer My Computer

At a glance

Windows 7 Ultimate x64
OS
Windows 7 Ultimate x64
Back
Top