Top-rated Batch recipes Code RecipesCount lines and words in a text file (Batch) 2017-04-28T08:22:08-07:00Antoni Gual <p style="color: grey"> Batch recipe 580791 by <a href="/recipes/users/4182514/">Antoni Gual</a> (<a href="/recipes/tags/word_count/">word_count</a>). Revision 2. </p> <p>Returns number of lines and words (separed by spaces) of a text file dragged to the script. Does'nt count blank lines. </p> Batch prime generator (Batch) 2017-04-25T11:44:27-07:00Antoni Gual <p style="color: grey"> Batch recipe 580789 by <a href="/recipes/users/4182514/">Antoni Gual</a> (<a href="/recipes/tags/primes/">primes</a>). Revision 3. </p> <p>Here is a radically differnt approach to generating primes in pure batch that overperforms everything else I have found . The idea comes from an exercise in Knuth's TAOCP Vol 3 page 617.</p> Batch Local Network Messaging System (Batch) 2012-02-03T01:41:41-08:00Alexander James Wallar <p style="color: grey"> Batch recipe 578028 by <a href="/recipes/users/4179768/">Alexander James Wallar</a> (<a href="/recipes/tags/alex/">alex</a>, <a href="/recipes/tags/batch/">batch</a>, <a href="/recipes/tags/batch_file/">batch_file</a>, <a href="/recipes/tags/dos/">dos</a>, <a href="/recipes/tags/messaging/">messaging</a>, <a href="/recipes/tags/messenger/">messenger</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/wallar/">wallar</a>, <a href="/recipes/tags/windows/">windows</a>, <a href="/recipes/tags/wired/">wired</a>, <a href="/recipes/tags/wired_network/">wired_network</a>). Revision 3. </p> <p>This is a Batch Local Messaging System that can be used to send messages between computers that share the same file system.</p> <p>There are three files in the code below. They are separated with dashed lines. There is a comment on the top of each segment of code indicating the file name that the code needs to be saved as. They need to be saved as three separate batch files in the same folder. </p> <p>The first file, MessengerMain.bat will ask you for your name and then an address. The name should be whatever you wish your screen name to be. The address needs to be the path of the FOLDER that is shared between you and the other computer that you are communicating with. Once these pieces of information are entered, two screens will appear. The first is the Sender screen and the other is the Receiver screen. </p> <p>How does it work? The MessengerMain.bat file will create two text files, Name.txt and Address.txt, that will hold your user name and the common folder address. It will then use the START command to run Sender.bat and Receiver.bat. Sender.bat will create a text file named msgtext.txt in the address folder you specified in MessengerMain.bat. If there is already a file of this sort in existence in the address folder, it will overwrite it. Once this file is created, any message you enter will be saved in the msgtext.txt file after the name you entered (%name%: %msg%). Sender.bat the CLS (clears) the screen and asks you for another message continuously. Receiver.bat is very similar. Receiver.bat, first off, reads the Address.txt file and the Name.txt file to find your information given in MessengerMain.bat just like Sender.bat does. It will count the number of lines in the msgtext.txt file and will clear the whole screen and print out the whole contents of the file if the number of lines in msgtext.txt increases. So basically you are writing to a shared file and reading from a shared file. </p> <p>Example:</p> <p>I have a folder called MSGFolder located in the folder as I have my MessengerMain.bat, Receiver.bat, and Sender.bat files. I then run MessengerMain.bat by double clicking on the icon. I enter Alex for my Name and MSGFolder as the Address. I then double click MessengerMain.bat again and enter the name Bob for Name and MSGFolder for Address. Once you do this you can type in either of the Sender.bat interfaces and it will show up as if you are talking. </p> Add days to a calendar date- Julian date (Batch) 2016-08-17T10:32:03-07:00Antoni Gual <p style="color: grey"> Batch recipe 580683 by <a href="/recipes/users/4182514/">Antoni Gual</a> (<a href="/recipes/tags/calendar/">calendar</a>). </p> <p>The trick to add days to a date is to convert the date to a serial, do a normal addition then convert the result back to a date. The serial I use here is the Julian day number used by the astronomers because its conversion formulas arewell documented. If you check the julian day number on internet the result can vary by a day, because julian days start at noon and i'm not making this distinction. </p> Get text length - Column left center and right alignement (Batch) 2016-06-15T06:42:00-07:00Antoni Gual <p style="color: grey"> Batch recipe 580682 by <a href="/recipes/users/4182514/">Antoni Gual</a> . </p> <p>The recipe parses some lines of text (separator=$), calculates the width of each column and prints the text in columns with lefr, right and center alignment. I have put the strlen and the alignment routines in separate procedures, to ease the reuse. The alignement procedures work in place, the result is returned in the same variable as the original string.</p> Permutations by recursive Heap's method (Batch) 2016-06-11T08:42:41-07:00Antoni Gual <p style="color: grey"> Batch recipe 580678 by <a href="/recipes/users/4182514/">Antoni Gual</a> (<a href="/recipes/tags/permutation/">permutation</a>, <a href="/recipes/tags/recursion/">recursion</a>). </p> <p>Setlocal / endlocal allow for recursion in batch. Values can be passed by value and by reference, the later can return a value to the caller.</p> Last sunday of each month for a given year (Batch) 2016-06-07T20:25:00-07:00Antoni Gual <p style="color: grey"> Batch recipe 580677 by <a href="/recipes/users/4182514/">Antoni Gual</a> (<a href="/recipes/tags/calendar/">calendar</a>). Revision 2. </p> <p>Includes batch routines for day of week, is leap year and last dat of the month</p> ASCII art Sphere with integer square root (Batch) 2016-06-06T10:09:38-07:00Antoni Gual <p style="color: grey"> Batch recipe 580673 by <a href="/recipes/users/4182514/">Antoni Gual</a> (<a href="/recipes/tags/ascii/">ascii</a>, <a href="/recipes/tags/graphics/">graphics</a>). Revision 2. </p> <p>The code draws a sphere in ASCII Art. Square root routine bt Aacini</p> Timing a batch program (Batch) 2016-05-29T10:50:33-07:00Antoni Gual <p style="color: grey"> Batch recipe 580670 by <a href="/recipes/users/4182514/">Antoni Gual</a> (<a href="/recipes/tags/batch/">batch</a>, <a href="/recipes/tags/timing/">timing</a>). </p> <p>It uses %time% to time a function to the hundredth of second.</p> Send and retrieve text to/from clipboard (Batch) 2016-05-27T09:56:56-07:00Antoni Gual <p style="color: grey"> Batch recipe 580669 by <a href="/recipes/users/4182514/">Antoni Gual</a> (<a href="/recipes/tags/batch/">batch</a>, <a href="/recipes/tags/clipboard/">clipboard</a>). </p> <p>Sending uses the command line tool clip.exe that may not be available in Windows XP. There is no standard tool to retrieve from clipboard so I use javascript via mshta.</p> Batch priority queue (Batch) 2016-05-26T11:00:21-07:00Antoni Gual <p style="color: grey"> Batch recipe 580666 by <a href="/recipes/users/4182514/">Antoni Gual</a> (<a href="/recipes/tags/batch/">batch</a>). </p> <p>The fact the environment sorts itself by key allows us to implement a PQ using the prefix "queu" added to the priority value as a key</p> File selector dialog in batch (Batch) 2017-03-27T13:20:41-07:00Antoni Gual <p style="color: grey"> Batch recipe 580665 by <a href="/recipes/users/4182514/">Antoni Gual</a> (<a href="/recipes/tags/batch/">batch</a>, <a href="/recipes/tags/directory/">directory</a>). Revision 2. </p> <p>Runs mshta hidden to open a file dialog and get the path of the file selected. No parameters can be passed to the dialog. EDITED: I did a subroutine with the snippet</p> Publish a Windows Process List to PDF with xtopdf (Batch) 2015-12-27T20:45:32-08:00Vasudev Ram <p style="color: grey"> Batch recipe 579142 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdfwriter/">pdfwriter</a>, <a href="/recipes/tags/pdf_generation/">pdf_generation</a>, <a href="/recipes/tags/processes/">processes</a>, <a href="/recipes/tags/process_management/">process_management</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>This recipe shows how you can generate a Windows process list or task list (basically, a list of running processes, with some information about each of them), to a PDF file, using the Windows TASKLIST command along with the xtopdf toolkit. The list is sorted in ascending order of memory usage of the processes, before writing it to PDF.</p> <p>It differs somewhat from other xtopdf recipes, in that no additional code needs to be written, over and above what is already in the xtopdf package. We just have to use the needed commands there, in a series of commands or a pipeline.</p> <p>However, one can still write additional code, by modifying the program used (, if needed, to customize the PDF output.</p> Unix head -n analog (Batch) 2013-10-12T17:40:06-07:00greg zakharov <p style="color: grey"> Batch recipe 578688 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/head/">head</a>). </p> <p>Reads first N strings in text file. It looks like <a href="">tail -n</a></p> Current month calendar (Batch) 2013-10-11T16:11:41-07:00greg zakharov <p style="color: grey"> Batch recipe 578687 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/calendar/">calendar</a>). </p> <p>Prints calendar at current month.</p> Download file (Batch) 2013-10-10T16:31:50-07:00greg zakharov <p style="color: grey"> Batch recipe 578680 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/download/">download</a>). </p> <p>Download file from internet without third party tools.</p> String length (Batch) 2013-10-10T16:27:48-07:00greg zakharov <p style="color: grey"> Batch recipe 578664 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/length/">length</a>, <a href="/recipes/tags/string/">string</a>). Revision 2. </p> <p>A way for checking string length.</p> Bash style commands (Batch) 2013-08-22T13:06:33-07:00greg zakharov <p style="color: grey"> Batch recipe 578649 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/cmd/">cmd</a>). </p> <p>This is just a concept. To import bash style commands use "script.cmd /bash", to get the list of imported commands use "script.cmd /map"</p> Search engine (Batch) 2013-10-10T16:18:09-07:00greg zakharov <p style="color: grey"> Batch recipe 578646 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/search/">search</a>). Revision 2. </p> <p>Quick search on files index embedded directly in the command script. For example: "search.cmd exe$" - looks for all EXE files in index or just "search.cmd blahblahblah" - looks for all matches with "blahblahblah" in paths. To remove index from script use "search.cmd /fix:me" command (without quotes).</p> Mounted devices2 (Batch) 2013-08-19T08:46:54-07:00greg zakharov <p style="color: grey"> Batch recipe 578645 by <a href="/recipes/users/4184115/">greg zakharov</a> . </p> <p>Another way to check mounted drives (this method has a bug with cdrom).</p>