Hi, Seems to me a specific place to ask questions regarding batch files would be useful and contribute to MDL being the place not just to download new concepts we use and love to play with so much but rather a place to see and learn how it all happens behind the scenes in an alternative application use forum. Here is a bat script example: Trilogy 4.2 Here are some helpful Web links to learn and play with these cmd's, switches and all that encompasses batch files that some developments at MDL are composed of http://www.computerhope.com/batch.htm http://www.robvanderwoude.com http://commandwindows.com/ http://www.aumha.org/a/batches.php http://ss64.com/nt/ Here are are some simple examples given to us by MDL members of certain command's and how you can use them in scripting in batch files Basics Change Console Color -- Color Display message -- ECHO Use Variables -- SET Conditional Statements -- IF Windows Console -- A Simple Menu Obtain script location -- %~dp0 more Looping Statements -- FOR Batch admin check - Perfected batch admin check Intermediate Creating Menu -- CHOICE,GOTO Using arguments -- SHIFT Subroutines -- CALL Advanced
I thought that people could both ask questions on how to script something as well as a place for advanced users to challenge beginners with questions on how a certain .bat file would be written while receiving help if needed: Example: How do you create a folder in a certain location with a certain name Answer: Code: mkdir "%SystemDrive%\Hey You"
Challenge #1: Write a batch file that takes one argument to display a diamond in numbers The single argument should be number. Eg. diamond.bat 5 will give the following output Code: 0 0 1 0 1 2 0 1 2 3 0 1 2 3 4 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 0 1 2 3 0 1 2 0 1 0
Something simple. Code: REM [dir] [/b] [*.extension]or[/A(=Files and Folders)]or[/S(=+subfolders)] [> outputfilename.txt] REM EXAMPLES REM [dir /b /A > List.txt] --> All Files And Folders REM [dir /b /S > List.txt] --> All Files And Folders Plus Those In Subfolders REM [dir /b *.bmp > List.txt] --> All BMPs via Wildcard REM [dir /b *.avi > List.txt] --> All AVIs via Wildcard dir /b *.* > List.txt Obviously these commands are used to create a list containing the names of all and/or specific files and folders contained in the directory you execute the .bat in. Useful for making batch-rename lists and all sorts of other things.
How would you do a batch file to check a .ini file on one of your installed programs and have it make a correction and save it? For instance - Find this in blah.ini: [Blah_Handle] Count=1 Handle1=197694 And change to: [Blah_Handle] Count=0
The following batch file will take four arguments Filename - Name of configuration file Section - Section to be modified Name - Name of the property Value - New value of the property Only drawback of this batch file is commented lines are ignored, so these lines get removed in the modified file. Code: @echo off setlocal enabledelayedexpansion if '%1' EQU '' goto :usage if '%2' EQU '' goto :usage if '%3' EQU '' goto :usage if '%4' EQU '' goto :usage set file=new.tmp if Exist new.tmp del /a new.tmp for /f "tokens=1,2 delims==" %%A in (%1) do ( set var=%%A set vat=!var:~1,-1! set vas=!var:~0,1! if '!vas!' EQU '[' ( echo %%A>>%file% if '!vat!' EQU '%2' ( set flag=1 ) ELSE ( set flag=0 ) ) ELSE ( if '!flag!' EQU '1' ( if '%%A' EQU '%3' ( echo %%A=%4>>%file% ) ELSE ( echo %%A=%%B>>%file% ) ) ELSE ( echo %%A=%%B>>%file% ) ) ) move new.tmp %1 >NUL exit /b :usage echo syntax: setin filename section name value
@ MD I was never good with batch files so where in the script is the .ini file name suppose to be at? Attached is an example of the actual .ini itself. Pretty much just need the batch to check if "Handle" is present if so delete it then check the Count and make sure it reads Count=0. So where it reads .... [TCUP_Handle] Count=1 <-------No matter what this vale is at 1 or -1 or w/e needs to be 0 Handle1=197694 [Information] bla ... Needs to be ... [TCUP_Handle] Count=0 [Information] bla ... So there is no space and the ini continues as normal then saves the changes.
lol...How bout any basics before we do conditions, variables, like simple cmd with switch (In tangent with stuff for advanced people) And how to find switches for certain cmd with cmd.exe Maybe explain what an argument is and demonstrate, etc...lol Just an suggestion so everybody and beginners like me can participate...lol Scripting Kindergarten...lol (For some of us)
I'd like to learn more so far I have basic knowledge of HTML and simple JavaScript usage and editing it's been a while tho
The scripting we're learning here is for windows not the web but maybe a thread could be started for web help?
No, I don't know anything about this kind of scripting, but I do know that you find it everywhere ... that's why I want to learn.
Where do you want to start from? The following list is based on my opinion Basics Display message -- ECHO Use Variables -- SET Conditional Statements -- IF Looping Statements -- FOR Intermediate Creating Menu -- CHOICE,GOTO Using arguments -- SHIFT Subroutines -- CALL
Absolute basics for me...lol Then I can put what I learn in first post as some kind of reference to start off with for those interested in learning this stuff. Plus then I will be able to be more helpful to beginners. Any other links other than the one I did in first post I can also put in first post as to add to the usefulness of this repository. What ideas do you have as how to use this thread other than we have mentioned? Thanks
I can just explain a command and give examples on how you can use it. Lets begin with ECHO ECHO command is used to display message on a console Code: Syntax: ECHO [ON | OFF] ECHO [message] ECHO OFF is used to hide the command from being displayed on the console. Commonly a batch file starts with @ECHO OFF. The @ stands for immediate effect of the command including the command itself. ECHO Hello World displays the message 'Hello World' on the console. To display a blank line the ECHO command should be followed by one of the following characters (.,:;\([]+) Eg. ECHO.
The SET command is used create variables. The actual usage of SET command is to display, add or remove environment variables. Type SET in command prompt and hit enter. It will display all the system environment variables. To expand a variable, % symbol is used. Eg. ECHO %WINDIR% is expanded to C:\Windows A variable can be assigned a value once and can be used throughout the batch file. Batch file without using variables Code: echo This is line 1 >>"E:\test\test 1\test 2\test.txt" echo This is line 2 >>"E:\test\test 1\test 2\test.txt" echo This is line 3 >>"E:\test\test 1\test 2\test.txt" echo This is line 4 >>"E:\test\test 1\test 2\test.txt" Batch file using variables Code: SET file="E:\test\test 1\test 2\test.txt" echo This is line 1 >>%file% echo This is line 2 >>%file% echo This is line 3 >>%file% echo This is line 4 >>%file% If you want to change the name of the file in the former code, you need to replace all the instances of the filename. In the latter code, you just need to change it once. SET command also allows you to do perform arithmetic operations on variables. SET /A expression Code: @ECHO OFF ECHO Basic Arithmetic Operations SET /a x=15 SET /a y=5 SET /a z=x+y ECHO %x% + %y% = %z% SET /a z=x-y ECHO %x% - %y% = %z% SET /a z=x*y ECHO %x% * %y% = %z% SET /a z=x/y ECHO %x% / %y% = %z% SET /a z=x%%y ECHO %x% %% %y% = %z% SET command allows you to set the value of a variable to a line of input entered by the user Syntax: SET /P varName=[promptString] Code: SET /P select="Do you wish to continue? (Y/N): " ECHO %select% The next thing you can do with variables is string manipulation. Concatenation Code: SET var1=Hello SET var2=World! SET var2=%var1% %var2% ECHO %var2% Substring Code: SET var=This is a very nice day! echo %var:~10% echo %var:~-10% echo %var:~10,-10% Replace a string within a variable Code: SET var=This is a very nice day! ECHO %var% ECHO %var:nice=beautiful%