/* Title : Text Report on Disk Usage Date : 20060214 1.00 Author : A.N.Suresh Kumar - Chennai, INDIA Mail : arian.suresh@gmail.com This script has been written to demonstrate the working of two functions NumStr() and SetWidth() which supplements FileAppend in creating formatted text files. For more, visit AutoHotkey forum Topic http://www.autohotkey.com/forum/viewtopic.php?t=7667 */ Report=DiskStat.txt FileDelete,%Report% FileAppend, * Drive Statistics for Computer Name: %A_ComputerName% *`n,%Report% FileAppend, .-----.--------------.------.--------------.--------------.`n,%Report% FileAppend, | DRV | PARTITION | SIZE | USED SPACE | FREE SPACE |`n,%Report% FileAppend, | | LABELNAME | .------.-------.------.-------|`n,%Report% FileAppend, | | | MB | MB | `%age | MB | `%age |`n,%Report% FileAppend, .-----.--------------.------.------.-------.------.-------.,%Report% Asc = 66 Loop,25 { Drive = % Chr(Asc) ":\" ifExist, %Drive% { DriveGet, Label, Label, %Drive% DriveGet, Total, capacity, %Drive% DriveSpaceFree, FreeSpace,%Drive% UsedSpace = % Total - FreeSpace UsedPRC = % (UsedSpace/Total) * 100 FreePRC = % (FreeSpace/Total) * 100 FileAppend, `n| %Drive% |,%Report% FileAppend, % SetWidth(Label ,13,1) " |",%Report% FileAppend, % SetWidth(Total ,5,2) " |",%Report% FileAppend, % SetWidth(UsedSpace,5,2) " |",%Report% FileAppend, % Numstr(usedPRC,6,2," ") " |" ,%Report% FileAppend, % SetWidth(FreeSpace,5,2) " |",%Report% FileAppend, % Numstr(freePRC,6,2," ") " |" ,%Report% } Asc+=1 } FileAppend, `n.-----.--------------.------.--------------.--------------.`n,%Report% run %Report% return NumStr(Value,Width,Dec,PadB4="") { SetFormat, float, .%Dec% Value+=0 Loop, { if (StrLen(Value) < Width) Value = % PadB4 Value else break } Return Value } SetWidth(Str,Width,AlignText) { If (AlignText!=0 and AlignText!=1 and AlignText!=2) AlignText=0 if AlignText=0 { RetStr= % (Str)Space(Width) StringLeft,RetStr,RetStr,%Width% } If AlignText=1 { Spaces:=(Width-(StrLen(Str))) RetStr= % Space(Round(Spaces/2))(Str)Space(Spaces-(Round(Spaces/2))) } if AlignText=2 { RetStr= % Space(Width)(Str) StringRight,RetStr,RetStr,%Width% } Return RetStr } Space(Width) { Loop,%Width% Space=% Space Chr(32) Return Space }