<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>Code snippets I’d like to remember, by Peter Forret
My ‘real’ blog is at blog.forret.com</description><title>Code Paparazzo</title><generator>Tumblr (3.0; @codepaparazzo)</generator><link>http://code.forret.com/</link><item><title>waRmZip - clean up folders by compressing, moving or deleting | Winadmin Tools</title><description>&lt;a href="http://winadmin.forret.com/post/8005353779/warmzip-clean-up-folders-by-compressing-moving-or"&gt;waRmZip - clean up folders by compressing, moving or deleting | Winadmin Tools&lt;/a&gt;: &lt;p&gt;&lt;pre&gt;waRmZip.wsf v1.7 (Nov 2005)
Utility to clean up/free up space in a folder (and its subfolders),
* compressing files after a certain number of days (with external program)
* rotating files after a certain number of days/above a certain size
* deleting files and/or empty folders after a certain period of time
* moving files to other folders/disks&lt;/pre&gt;&lt;/p&gt;</description><link>http://code.forret.com/post/8005912101</link><guid>http://code.forret.com/post/8005912101</guid><pubDate>Sun, 24 Jul 2011 19:10:00 +0200</pubDate></item><item><title>CMD: calculate throughput</title><description>&lt;pre&gt;:: start doing %NB% things
call :calsectime
set TIME1=%SECTIME%

::(do stuff)

:: finished doing %NB% things
call :calsectime
set TIME2=%SECTIME%

set /A TPS=%NB% / ( %TIME2% - %TIME1% )
echo Thoughput = %TPS% things/sec

:calcsectime
	set NOW=%TIME:~0,8%
	for /F "delims=: tokens=1,2,3" %%f in ( "%NOW%" ) do (
		SET /A SECTIME=%%h + %%g * 60 + %%f * 3600
		)
	goto :EOF
&lt;/pre&gt;
&lt;p&gt;Remarks:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;I calculate the # seconds since midnight, so if you start something just before midnight, and end just after, it will not work, you will get a negative nonsense throughput (TIME2 &amp;lt; TIME1)&lt;/li&gt;
&lt;/ul&gt;</description><link>http://code.forret.com/post/7922729246</link><guid>http://code.forret.com/post/7922729246</guid><pubDate>Fri, 22 Jul 2011 12:00:05 +0200</pubDate><category>cmd</category></item><item><title>CMD: free space in MB of a disk</title><description>&lt;pre class="brush: cmd;"&gt;:freespace
	dir %1 2&amp;gt;&amp;amp;1 | findstr free &amp;gt; %TMPFILE%
	for /f "tokens=3,4*" %%f in ( %TMPFILE% ) do (
		set FREEBYTES=%%f
	)
	set FREEBYTES=%FREEBYTES:.=%
	set FREEBYTES=%FREEBYTES:,=%
	set /a FREEMB=%FREEBYTES:~0,-6%
	goto :end
&lt;/pre&gt;
&lt;p&gt;Some remarks:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;CMD DOS can only handle 32 bit signed integer, so the sizes of disks over 2GB are impossible to store as bytes. I convert the number to MB by ignoring the last 6 chars (equivalent to dividing by 1.000.000, but as a string operation, not a number division)&lt;/li&gt;
&lt;li&gt;Depending on the language of the Windows you have, numbers will be shown as 1.234.567.890 or 1,234,567,890. I remove these separators.&lt;/li&gt;
&lt;/ul&gt;</description><link>http://code.forret.com/post/7884721909</link><guid>http://code.forret.com/post/7884721909</guid><pubDate>Thu, 21 Jul 2011 16:00:00 +0200</pubDate><category>cmd</category></item><item><title>CMD: calculate folder size</title><description>&lt;pre class="brush: cmd;"&gt;call :foldersize c:\temp
...
:foldersize
	if not exist %1 (
		echo *** WARNING: folder [%1] does not exist!
		set MBFOLDER=0
		goto :EOF
	)
	dir %1 2&amp;gt;&amp;amp;1 | findstr File &amp;gt; %TMPFILE%
	for /f "tokens=1,2,3,4*" %%f in ( %TMPFILE% ) do (
		set NBFILES=%%f
		set NBBYTES=%%h
	)
	set NBBYTES=%NBBYTES:.=%
	set NBBYTES=%NBBYTES:,=%
	set /a MBFOLDER=%NBBYTES:~0,-6%
	goto :EOF
&lt;/pre&gt;
&lt;p&gt;Remarks:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;Because DOS integers (signed 32 bit) cannot be used to hold the # of bytes, I use the output of &lt;code&gt;DIR&lt;/code&gt; and ignore the last 6 numbers, which gives me an approximation in MB.&lt;/li&gt;
&lt;li&gt;Because of the rounding down to the nearest MB, this will not work for a folder with a lot of small files&lt;/li&gt;
&lt;li&gt;I write to a TMPFILE temporary file, which I have defined earlier, &lt;code&gt;%TMP%\tmp_%USERNAME%.txt&lt;/code&gt; is a e.g. good option. &lt;/li&gt;
&lt;li&gt;I could work with for /f &amp;#8220;usebackquote&amp;#8221;, but since I often use keyboards without ` (they exist) and it&amp;#8217;s hard to do 2 piped commands between backquotes&lt;/li&gt;
&lt;li&gt;This example was made for the English version of Windows: DIR has a line with the word ‘File’. If you use another language, adapt as necessary&lt;/li&gt;
&lt;/ul&gt;</description><link>http://code.forret.com/post/7883392833</link><guid>http://code.forret.com/post/7883392833</guid><pubDate>Thu, 21 Jul 2011 14:52:00 +0200</pubDate><category>cmd</category></item><item><title>CMD: Find LABEL of a disk</title><description>&lt;pre class="brush: cmd;"&gt;:findlabel
	dir %1  2&amp;gt;&amp;amp;1 | findstr /C:"drive" &amp;gt; %TMPFILE%
	for /f "tokens=6,7*" %%f in ( %TMPFILE% ) do (
		set DRVLABEL=%%f
		)
	set DRVLABEL=%DRVLABEL: =%
	goto :EOF
&lt;/pre&gt;
&lt;p&gt;Remarks:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;I write to a TMPFILE temporary file, which I have defined earlier, %TMP%\tmp_%USERNAME%.txt is a e.g. good option. &lt;/li&gt;
&lt;li&gt;I could work with for /f “usebackquote”, but since I often use keyboards without ` (they exist) and it’s hard to do 2 piped commands between backquotes&lt;/li&gt;
&lt;li&gt;This example was made for the English version of Windows: DIR has a line with the word &amp;#8216;drive&amp;#8217;. If you use another language, adapt as necessary&lt;/li&gt;
&lt;/ul&gt;</description><link>http://code.forret.com/post/7883166939</link><guid>http://code.forret.com/post/7883166939</guid><pubDate>Thu, 21 Jul 2011 14:39:00 +0200</pubDate><category>cmd</category></item></channel></rss>

