{"id":1144,"date":"2014-09-19T14:54:03","date_gmt":"2014-09-19T14:54:03","guid":{"rendered":"http:\/\/scunster.co.uk\/?p=1144"},"modified":"2014-09-19T15:04:39","modified_gmt":"2014-09-19T15:04:39","slug":"work-out-directory-sizes-in-gb-and-mb-in-a-bat-file","status":"publish","type":"post","link":"https:\/\/scunster.co.uk\/?p=1144","title":{"rendered":"Work out directory sizes in gB and MB in a bat file"},"content":{"rendered":"<p>This little bat file is cobbled together from 3 other files that nearly achieved what I was after but none of them could do gB and MB<\/p>\n<p>Basically, this will scan a folder and give the total size of all files and folders within it and return the output in MB and gB as opposed to the bat \/ dos usual which is just in bytes!<\/p>\n<p>Just save the following as size.bat and run it as follows<br \/>\nsize.bat path\\to\\directory<\/p>\n<p>example<\/p>\n<pre>size.bat c:\\windows<\/pre>\n<p>Here&#8217;s the code<\/p>\n<pre>:size\r\nset savepath=%1\r\n@echo off\r\nsetLocal EnableDelayedExpansion\r\nset \/a value=0\r\nset \/a sum=0\r\nFOR \/R %savepath% %%I IN (*) DO (\r\nset \/a value=%%~zI\/1024\r\nset \/a sum=!sum!+!value!\r\n)\r\nset \/a meg=!sum!\/1024\r\nset \/a gig=!meg!\/1024\r\nREM This section shows the following message if\r\nREM the size if over 1gB\r\nREM It also writes the information to the file\r\nREM dirsize.txt in the root of the folder scanned\r\nif %gig% LSS 1 goto undergig\r\necho Total backup is approx !gig!gB or to be more precise !meg!MB &gt;&gt; &quot;%savepath%\\dirsize.txt&quot;\r\ngoto end\r\n\r\n:undergig\r\nREM this section just displays the following message\r\nREM if the directory size is under 1gb\r\nREM it also writes the information to the file\r\nREM dirsize.txt in the root of the folder scanned\r\necho Total backup is under a gB or to be more precise !meg!MB &gt;&gt; &quot;%savepath%\\dirsize.txt&quot;\r\ngoto end\r\n\r\n:end\r\npause<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This little bat file is cobbled together from 3 other files that nearly achieved what I was after but none of them could do gB and MB Basically, this will scan a folder and give the total size of all files and folders within it and return the output in MB and gB as opposed [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[197,126,227,224,226,225,223],"class_list":["post-1144","post","type-post","status-publish","format-standard","hentry","category-windows","tag-bat","tag-directory","tag-gb","tag-gig","tag-mb","tag-meg","tag-size"],"_links":{"self":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1144"}],"version-history":[{"count":6,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1144\/revisions"}],"predecessor-version":[{"id":1151,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1144\/revisions\/1151"}],"wp:attachment":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}