/* +-----------------------------------------------------------+ | A Demo for SetWidth() function. | | This script lists the contents of your Windows folder | | to WINDIR.TXT in a "TABULAR Format" with 3 columns. | | | | Column 1: "File Name" - 55 Chars Wide, Left Aligned | | Column 2: "File Size" - 12 Chars Wide, Right Aligned | | Column 3: "Last Modified" - 12 Chars Wide, Center Aligned | | | | Note: | | SetWidth() requires Space() included @ bottom | | I have avoided using extended ASCII characters (for table)| | to maintain the readability of the output text file | +-----------------------------------------------------------+ */ AutoTrim,Off ListFiles=%windir%\*.* Outfile=windir.txt FileDelete, %OutFile% FileAppend,* Listing Folder Contents * [ %ListFiles% ]`n,%OutFile% FileAppend,+-------------------------------------------------------+-------------+------------+`n,%OutFile% FileAppend,|File Name | File Size | Last |`n,%OutFile% FileAppend,| | (in Bytes)| Modified |`n,%OutFile% FileAppend,+-------------------------------------------------------+-------------+------------+`n,%OutFile% Loop,%Listfiles% { FileName:=A_LoopFileName FileGetSize,FileSize,%A_LoopFileLongPath% FileGetTime,FileTime,%A_LoopFileLongPath% FormatTime,DateStamp,%FileTime%,yyyy-MM-dd FileAppend,% "|" SetWidth(FileName,55,0) "|" SetWidth(FileSize,12,2) " |" SetWidth(DateStamp,12,1) "|" "`n" ,%OutFile% } FileAppend,+-------------------------------------------------------+-------------+------------+`n,%OutFile% FileAppend,=> This file was created by "%A_Scriptname%" running in AutoHotkey version %A_AhkVersion%`n,%OutFile% run, %OutFile% return SetWidth(Str,Width,AlignText) { /* +--------------------------------------------------+ | SetWidth increases a String's length by adding | | spaces to it and Aligns it Left/Center/Right | | | | Parameters: | | Str: The String to be processed | | Width: The length of the String (to be returned) | | AlignText: 0=Left, 1=Center, 2=Right | | | | AutoHotkey function written by: | | Suresh, arian.suresh@gmail.com [2006-02-05] | +--------------------------------------------------+ */ 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 }