<p>I'd like to keep a "compile-counter" for one of my projects. I figured a quick and dirty way to do this would be to keep a text file with a plain number in it, and then simply call upon a small script to increment this each time I compile.</p>

<p>How would I go about doing this using the regular Windows command line?</p>

<p>I don't really feel like installing some extra shell to do this but if you have any other super simple suggestions that would accomplish just this, they're naturally appreciated as well.</p>

[{'answer_id': 40826, 'author': 'Steven Murawski', 'author_id': 1233, 'author_profile': 'https://Stackoverflow.com/users/1233', 'pm_score': 2, 'selected': False, 'text': '<p>It would be an new shell (but I think it is worth it), but from PowerShell it would be </p>\n\n<pre><code>[int](get-content counter.txt) + 1 | out-file counter.txt\n</code></pre>\n'}, {'answer_id': 40856, 'author': 'Re0sless', 'author_id': 2098, 'author_profile': 'https://Stackoverflow.com/users/2098', 'pm_score': 1, 'selected': False, 'text': '<p>If you don\'t mind running a Microscoft Windows Based Script then this jscript will work OK. just save it as a .js file and run it from dos with "wscript c:/script.js".</p>\n\n<pre><code>var fso, f, fileCount;\nvar ForReading = 1, ForWriting = 2;   \nvar filename = "c:\\\\testfile.txt";\nfso = new ActiveXObject("Scripting.FileSystemObject");\n\n//create file if its not found\nif (! fso.FileExists(filename))\n{\n  f = fso.OpenTextFile(filename, ForWriting, true);\n  f.Write("0");\n  f.Close();\n}\n\nf = fso.OpenTextFile(filename, ForReading);\nfileCount = parseInt(f.ReadAll());\n\n//make sure the input is a whole number\nif (isNaN(fileCount))\n{\n    fileCount = 0;  \n}\n\nfileCount = fileCount + 1;\n\nf = fso.OpenTextFile(filename, ForWriting, true);\nf.Write(fileCount);\nf.Close();\n</code></pre>\n'}, {'answer_id': 40869, 'author': 'crono', 'author_id': 1462, 'author_profile': 'https://Stackoverflow.com/users/1462', 'pm_score': 5, 'selected': True, 'text': '<p>You can try a plain old batchfile.</p>\n\n<pre><code>@echo off\nfor /f " delims==" %%i in (counter.txt) do set /A temp_counter= %%i+1\necho %temp_counter% &gt; counter.txt\n</code></pre>\n\n<p>assuming the count.bat and counter.txt are located in the same directory.</p>\n'}, {'answer_id': 40899, 'author': 'Tom', 'author_id': 3715, 'author_profile': 'https://Stackoverflow.com/users/3715', 'pm_score': 2, 'selected': False, 'text': "<p>I'd suggest just appending the current datetime of the build to a log file.  </p>\n\n<pre><code>date &gt;&gt; builddates.txt\n</code></pre>\n\n<p>That way you get a build count via the # of lines, and you may also get some interesting statistics if you can be bothered analysing the dates and times later on.</p>\n\n<p>The extra size &amp; time to count the number of lines in the file will be insignificant unless you are doing seriously fast project iterations!</p>\n"}]
['https://Stackoverflow.com/questions/40787', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/914/']