Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: File List Sorted by Size
Is there another way to get a listing of the files in a folder sorted by Size?
thedir="C:\Winnt\Temp" ;Search directory thelist=fileitemize(Strcat(thedir,"*.*")) ;retrieves unsorted list askitemlist("Unsorted list of files",thelist,@tab,@unsorted,@single);debugging here count=itemcount(thelist,@tab);counts items in list recsize=280;record size buff=BinaryAlloc(recsize*count) For x= 1 to count thefile=itemextract(x,thelist,@tab) thesize=filesize(strcat(thedir,thefile)) thefile=strfix(thefile," ",260) ;padding the string thesize=strfixcharl(thesize,0,20) ;left padding of string with 0 thefile=strcat(thefile,thesize) binarypokeStr(buff, (x-1)*recsize, thefile) Next BinarySort(buff,recsize,260,20,@ascending|@STRING) ;sort size For x=1 to count line=BinaryPeekstr(buff,(x-1)*recsize,260) line=strtrim(line) if x==1 newlist=line else newlist=StrCat(newlist,@Tab,line) endif next askitemlist("Files listed by size",newlist,@tab,@unsorted,@single) message("all","Done")
;Here's another approach... ;---------------------------------------- ; Build a list of files sorted by size ;---------------------------------------- List1 = FileItemize(Strcat(TheDirectory,"\*.*")) ListCount = ItemCount(List1,@TAB) List2 = "" For X = 1 to ListCount File = ItemExtract(X,List1,@TAB) Size = FileSize(StrCat(TheDirectory,"\",File)) Size = StrFixLeft(Size,"0",12) List2 = ItemInsert(StrCat(Size,File),-1,List2,@TAB) Next SortedList = ItemSort(List2,@TAB) ;---------------------------------------- ; You now have a sorted list of sizes ; and files. You can use it like this. ;----------------------------------------- for X = 1 to ListCount Item = ItemExtract(x,SortedList,@TAB) File = StrSub(Item,13,-1) Size = StrSub(Item,1,12) ; Do something with them Next
Article ID: W14847
File Created: 2001:11:08:12:40:22
Last Updated: 2001:11:08:12:40:22