<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Tech-Recipes - Latest Comments in Using variables in Windows batch files</title><link>http://tech-recipes.disqus.com/</link><description>Cookbook of Tech Tutorials</description><atom:link href="https://tech-recipes.disqus.com/using_variables_in_windows_batch_files_batch_file_programming_tech_recipes/latest.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Tue, 26 Apr 2011 09:51:14 -0000</lastBuildDate><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-192029622</link><description>&lt;p&gt;I don't like Windows-style data output and using %date:~6,4%-%date:~3,2%-%date:~0,2% for backup, it gives YYYY-MM-DD format&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Andrew Basta</dc:creator><pubDate>Tue, 26 Apr 2011 09:51:14 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-159465965</link><description>&lt;p&gt;I like the nested () after the do in the for loop.  But seem to be having problems with nested for loops within it, as I want to take the first loop variable and add the second loop variable to it using the SET /A command...doesn't seem to work.  would be a great way to increment or decrement a number for file manipulation....&lt;br&gt;any ideas?&lt;br&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">sonoma</dc:creator><pubDate>Wed, 02 Mar 2011 18:55:40 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-144590067</link><description>&lt;p&gt;The next code does the job. I know it does the job using a different approach, but I guess the end result is the same as you wanted it.&lt;br&gt;Hope it helps...&lt;br&gt;Note: Because of the line "set /a count=%count%+1" this script works well under cmd, but not under good old &lt;a href="http://command.com" rel="nofollow noopener" target="_blank" title="command.com"&gt;command.com&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;SET count=0&lt;/p&gt;&lt;p&gt;:new_col&lt;br&gt;set /a count=%count%+1&lt;br&gt;if %count%==9 goto end&lt;br&gt;SET Colour=Colour%count%&lt;br&gt;goto get_col&lt;/p&gt;&lt;p&gt;:get_col&lt;br&gt;if "%Colour%"=="Colour1" set Colour=BLACK&lt;br&gt;if "%Colour%"=="Colour2" set Colour=BLUE&lt;br&gt;if "%Colour%"=="Colour3" set Colour=GREEN&lt;br&gt;if "%Colour%"=="Colour4" set Colour=CYAN&lt;br&gt;if "%Colour%"=="Colour5" set Colour=RED&lt;br&gt;if "%Colour%"=="Colour6" set Colour=PURPLE&lt;br&gt;if "%Colour%"=="Colour7" set Colour=ORANGE&lt;br&gt;if "%Colour%"=="Colour8" set Colour=GRAY&lt;br&gt;goto show_col&lt;/p&gt;&lt;p&gt;:show_col&lt;br&gt;ECHO Colour is %Colour%&lt;br&gt;goto new_col&lt;/p&gt;&lt;p&gt;:end&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Potranquito</dc:creator><pubDate>Fri, 11 Feb 2011 01:16:40 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-107843479</link><description>&lt;p&gt;have you found the answer? I have the same problem&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jalal ud Din</dc:creator><pubDate>Mon, 06 Dec 2010 07:14:49 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-88516809</link><description>&lt;p&gt;How about answering the question 'using variables in batch files' ...&lt;br&gt;printing the variables doesn't really amount to 'use'&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Me</dc:creator><pubDate>Wed, 20 Oct 2010 10:27:50 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-88456915</link><description>&lt;p&gt;When you've learned this it's easy to use it for backup purposes, like this one:&lt;/p&gt;&lt;p&gt;-----------------------------------------------------------------------------&lt;br&gt;md "C:\test\Backup %date%"&lt;br&gt;set bkpdir="C:\test\Backup %date%"&lt;/p&gt;&lt;p&gt;xcopy C:\temp %bkpdir% /E /C /Q /H /Y&lt;br&gt;-----------------------------------------------------------------------------&lt;/p&gt;&lt;p&gt;All you have to do is schedule this script to run each night or whenever you like, using windows scheduler. Works like a charm :)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Phatsta</dc:creator><pubDate>Wed, 20 Oct 2010 04:17:38 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-85729202</link><description>&lt;p&gt;Thanks, just needed this for my tutorial! :D&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">OrangeBoxTutorials</dc:creator><pubDate>Sun, 10 Oct 2010 16:28:55 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-78801123</link><description>&lt;p&gt;Hello,&lt;br&gt;In bat scripting how can i get the value of a variable within a variable.&lt;br&gt;Ex:&lt;br&gt;SET Colour1=RED&lt;br&gt;SET Colour2=BLUE&lt;br&gt;SET Colour3=GREEN&lt;br&gt;SET count=1&lt;br&gt;SET Colour=Colour%count%&lt;br&gt;ECHO Colour is %Colour%&lt;/p&gt;&lt;p&gt;Now Color shows Color1, as output...&lt;br&gt;How can i get Colour to show value of Color1 ie RED&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Helpme</dc:creator><pubDate>Sat, 18 Sep 2010 05:02:13 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-76659763</link><description>&lt;p&gt;I want to make a folder with the name of input argument in to the .bat file from .c file.&lt;/p&gt;&lt;p&gt;::assume the input argument is '5'&lt;/p&gt;&lt;p&gt;@echo off&lt;br&gt;ECHO DirName %1%  ::confirm the input (Display DirName 5)&lt;/p&gt;&lt;p&gt;set f = %1%   ::assigning the argument&lt;/p&gt;&lt;p&gt;MD f   :: here what I want is to make a folder name, 5  (line 7)&lt;/p&gt;&lt;p&gt;copy 1.jpg  f\1.jpg :: I want to copy the jpg to newly made folder.  (line 9)&lt;/p&gt;&lt;p&gt; But these line 7 and 9 gives Syntax errors&lt;/p&gt;&lt;p&gt;please help me someone&lt;/p&gt;&lt;p&gt;::ECHO C:\TEMP FOLDER ALREADY EXISTS&lt;br&gt;copy 1.jpg 1\1.jpg&lt;/p&gt;&lt;p&gt;pause&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Itsmeisuru</dc:creator><pubDate>Fri, 10 Sep 2010 09:09:46 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-75930616</link><description>&lt;p&gt;ahh! you can do this via a variable in the batch file.  you'd need to files or use functions to do this.&lt;/p&gt;&lt;p&gt;so we have two files; input.bat and variable.bat&lt;/p&gt;&lt;p&gt;we will have a command in input.bat that creates a basic directory listing of a folder and then can pass the  variable onto the variable.bat which will then echo the results to a log.txt file.&lt;/p&gt;&lt;p&gt;variable.bat:&lt;br&gt;echo %1 &amp;gt;&amp;gt; log.txt&lt;/p&gt;&lt;p&gt;input.bat&lt;br&gt;for /f "tokens=1 delims=\" %%a in ('dir /b "C:\"') do (variable.bat %%a)&lt;/p&gt;&lt;p&gt;it should do a dir with bare flag, C:\  and then send just the folder names to the variable.bat.  the %1 is the variable thats read from the input.bat.  you can use %1 %2 %3 and have 3 variables passed :)&lt;/p&gt;&lt;p&gt;hope that helps!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">seamonkey420</dc:creator><pubDate>Wed, 08 Sep 2010 00:53:11 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-73347359</link><description>&lt;p&gt;Could sombody pl help me on this&lt;/p&gt;&lt;p&gt;How can i set output of some command to a variable in batch file?&lt;br&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Lakshmi</dc:creator><pubDate>Tue, 31 Aug 2010 03:09:45 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-73334960</link><description>&lt;p&gt;how to get ip address if i use ipconfig &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Amdo</dc:creator><pubDate>Tue, 31 Aug 2010 02:11:58 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-72951038</link><description>&lt;p&gt;Thanks!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Shiki</dc:creator><pubDate>Sun, 29 Aug 2010 06:57:28 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-72753221</link><description>&lt;p&gt;tnks for the information!!!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">kirkjoserey</dc:creator><pubDate>Sat, 28 Aug 2010 01:07:11 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-70067817</link><description>&lt;p&gt;is there a way to take say &lt;br&gt; 1.txt, 2.exe, 3.jpg&lt;br&gt; and put them in to "4.rar"&lt;br&gt;i just want to rar my files before i send them off in the email my bat file sends..&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">HxCxK</dc:creator><pubDate>Thu, 19 Aug 2010 15:40:38 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-70067425</link><description>&lt;p&gt;That sounds like a sticky situation, im sure that it would be possible but not from the "web side of things"&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">HxCxK</dc:creator><pubDate>Thu, 19 Aug 2010 15:38:17 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-67535599</link><description>&lt;p&gt;I have files with same name in multiple folders say 123.txt in folder1,foder2...folder9 in C drive. I want to copy all this files to d:\test folder by appending them with alphabet or as a.txt, b.txt ...h.txt etc.. in sequence. Any help is appreciated.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">JS</dc:creator><pubDate>Tue, 10 Aug 2010 06:43:02 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-66747386</link><description>&lt;p&gt;I need to connect to database and need to get the values from table and store in a variable in bat file can any one help me on this asap ...&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">satheesh</dc:creator><pubDate>Fri, 06 Aug 2010 05:41:48 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-65433251</link><description>&lt;p&gt;thanks budy....................&lt;/p&gt;&lt;p&gt;jitender &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jityahoo</dc:creator><pubDate>Sat, 31 Jul 2010 07:44:26 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-64650593</link><description>&lt;p&gt;Is it making the grinding noise? If so the PC is suspect and you need to call Microsoft. It happen to me.  :-(&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Sanjay</dc:creator><pubDate>Tue, 27 Jul 2010 11:56:54 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-63840978</link><description>&lt;p&gt;@ECHO OFF&lt;br&gt;rem set N=%1%&lt;br&gt;set N=100&lt;br&gt;FOR /L %%X IN (12,1,%N%)do (&lt;br&gt;  echo "X i %%X"&lt;br&gt;  set FL=153_%%X.rar&lt;br&gt;  echo %FL%  &lt;br&gt;  rem copy  153_1.rar %FL%&lt;br&gt;  copy  153_1.rar 153_%%X.rar&lt;br&gt;)&lt;/p&gt;&lt;p&gt;above script creates 88 files. It copy 153_1.rar file to 153_12.rar, 153_13.rar ....153_100.rar &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Bharat Patel</dc:creator><pubDate>Fri, 23 Jul 2010 03:08:13 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-62330395</link><description>&lt;p&gt;Hey,&lt;/p&gt;&lt;p&gt;i was wondering a long time ago if it was possible to use the value of one variable, in order to define another.&lt;/p&gt;&lt;p&gt;example:&lt;/p&gt;&lt;p&gt;set /p var1=Please enter a number:&lt;br&gt;set /a value=string%var1%&lt;br&gt;echo %value%&lt;/p&gt;&lt;p&gt;any help would be greatly appreciated&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Daniel</dc:creator><pubDate>Thu, 15 Jul 2010 01:42:22 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-60127325</link><description>&lt;p&gt;nice one,easy to go thru &lt;br&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mayini</dc:creator><pubDate>Thu, 01 Jul 2010 08:43:38 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-36094049</link><description>&lt;p&gt;I want to create a batch file that looks at a list of files, and zips like files together, then deletes the files that were zipped.&lt;/p&gt;&lt;p&gt;Example: a folder contains:&lt;/p&gt;&lt;p&gt;&lt;a href="http://file1.xyz" rel="nofollow noopener" target="_blank" title="file1.xyz"&gt;file1.xyz&lt;/a&gt;&lt;br&gt;&lt;a href="http://file1_6.abc" rel="nofollow noopener" target="_blank" title="file1_6.abc"&gt;file1_6.abc&lt;/a&gt;&lt;br&gt;&lt;a href="http://file2_1.abc" rel="nofollow noopener" target="_blank" title="file2_1.abc"&gt;file2_1.abc&lt;/a&gt;&lt;br&gt;&lt;a href="http://file3.xyz" rel="nofollow noopener" target="_blank" title="file3.xyz"&gt;file3.xyz&lt;/a&gt;&lt;br&gt;&lt;a href="http://file3_0.abc" rel="nofollow noopener" target="_blank" title="file3_0.abc"&gt;file3_0.abc&lt;/a&gt;&lt;/p&gt;&lt;p&gt;The batch file should:&lt;br&gt;1) combine &lt;a href="http://file1.xyz" rel="nofollow noopener" target="_blank" title="file1.xyz"&gt;file1.xyz&lt;/a&gt; and &lt;a href="http://file1_6.abc" rel="nofollow noopener" target="_blank" title="file1_6.abc"&gt;file1_6.abc&lt;/a&gt; into a file called &lt;a href="http://file1_6.zip" rel="nofollow noopener" target="_blank" title="file1_6.zip"&gt;file1_6.zip&lt;/a&gt;&lt;br&gt;2) skip &lt;a href="http://file2_1.abc" rel="nofollow noopener" target="_blank" title="file2_1.abc"&gt;file2_1.abc&lt;/a&gt; (since it has no other file "like" it)&lt;br&gt;3) combine &lt;a href="http://file3.xyz" rel="nofollow noopener" target="_blank" title="file3.xyz"&gt;file3.xyz&lt;/a&gt; and &lt;a href="http://file3_0.abc" rel="nofollow noopener" target="_blank" title="file3_0.abc"&gt;file3_0.abc&lt;/a&gt; into a file called &lt;a href="http://file3_0.zip" rel="nofollow noopener" target="_blank" title="file3_0.zip"&gt;file3_0.zip&lt;/a&gt;&lt;br&gt;4) delete &lt;a href="http://file1.xyz" rel="nofollow noopener" target="_blank" title="file1.xyz"&gt;file1.xyz&lt;/a&gt;, &lt;a href="http://file1_6.abc" rel="nofollow noopener" target="_blank" title="file1_6.abc"&gt;file1_6.abc&lt;/a&gt;, &lt;a href="http://file3.xyz" rel="nofollow noopener" target="_blank" title="file3.xyz"&gt;file3.xyz&lt;/a&gt;, &lt;a href="http://file3_0.abc" rel="nofollow noopener" target="_blank" title="file3_0.abc"&gt;file3_0.abc&lt;/a&gt; (since they are now in a new zip file)&lt;/p&gt;&lt;p&gt;This is just a simple example - the actual file list may consist of 100's of files...&lt;/p&gt;&lt;p&gt;Right now I create a list of the files with the dir command, import into excel, go through a whole lot of mmanipulation to create a batch file that contains a line of code for every specific file combination.  I'd like to use variables and looping? to recurse the directory to perform the needed actions.&lt;/p&gt;&lt;p&gt;HELP!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Rich</dc:creator><pubDate>Tue, 23 Feb 2010 12:39:53 -0000</pubDate></item><item><title>Re: Using variables in Windows batch files</title><link>http://www.tech-recipes.com/rx/630/using-variables-in-windows-batch-files/#comment-33421042</link><description>&lt;p&gt;this stuff is old news to me now if anyone knows how to increase or decreese a varrible then please tell me&lt;/p&gt;&lt;p&gt;but if you want a rpglike battle system in batch email me at&lt;br&gt;rater193@gmail.com&lt;br&gt;it works just as well as increesing or decreesing varribles&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">rater193</dc:creator><pubDate>Wed, 10 Feb 2010 11:54:03 -0000</pubDate></item></channel></rss>