Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Help with a little batch file

07 Feb 2011   #1
masca90020

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
.
07 Feb 2011   #2
allend66

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
07 Feb 2011   #3
Ztruker

Windows 10 Pro X64
 
 

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
.

07 Feb 2011   #4
masca90020

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
07 Feb 2011   #5
Scr1ptW1zard

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
08 Feb 2011   #6
masca90020

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




Thread Tools




Similar help and support threads
Thread Forum
How can I write a batch file that opens a file in a program?
I wrote this batch file which does what I want it to do so far. @echo off "C:\Users\xxxxxx\Documents\HideTaskbar\HideTaskbar.exe" "C:\Program Files (x86)\VideoLANold\VLC\vlc.exe" "C:\Users\xxxxxx\Documents\HideTaskbar\ShowTaskbar.exe" exit
General Discussion
I need a batch file to open a random file within a certain folder/path
I want a batch to select and open a random link file in a folder i have. All the links are music videos I like to listen to, and I kind of want to just have an option for 'surprise me!'. I can change the file names if I have to, and I have a basic batch file ability. I know the simple commands,...
General Discussion
How to run a batch file at logoff & some batch scripting help please
Hiya, I'd just like to run a simple batch file at logoff to backup some settings. I plan to use Robocopy, which is what i use to more thorough backups. Two questions: 1. How make it run by clicking Start > Shutdown? (i realise i could make a shutdown batch file and run it instead, but i'd...
Backup and Restore
Batch File that grabs file names from folder to insert into batch file
Ok I'm totally at a loss on how to word this so I'm just going to write it out the best that I can... :confused: First I have a batch file that I'm writing that will convert mp4 files to mp3 files (I have a lot) for a buddies band using ffmpeg. Here's the code that I'm using: ffmpeg -i...
General Discussion
batch file open file for program in the startup folder
I have a computer that is a drone specifically for an outside LED sign. This computer is designed to never shut off and doesn't have any other program on it besides Operating System and the sign software. I need to create a batch file that I can place in the "start-up" folder that will open the...
General Discussion
How to create a batch file that will move files based on the file type
How to create a batch file that will move files based on the file type? My Requirement : I need a batch file to copy all .doc files in all my HardDisk to a removable disk say (Z: drive) . Can anyone make it possible using a batch file?Please...Its urgent...
General Discussion


Our Sites

Site Links

About Us

Find Us

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

All times are GMT -5. The time now is 23:57.
Twitter Facebook Google+ Seven Forums iOS App Seven Forums Android App