Jan 24, 2008

Tip: Counting Files by Date

We like to know the number of the certain special type file processed month by month.
The following code will do the job:

(* all the files under one base direcotry *)
SetDirectory[basedirectory]
(* find all the files in all the subdirectories*)
files = FileNames["*.byt", {"*"}, Infinity];

(* return {year, month} for each file *)
data = Take[FileDate[basedirectory <> "\\" <> #], 2] & /@ files;
(* sort then count *)
cs = Tally[Sort[data]];

(* draw the graph *)
DateListPlot[cs, Filling -> Bottom, FillingStyle -> Blue, PlotStyle -> {Red, PointSize[Large]}, PlotRange -> {{{2006, 1}, {2008, 2}}, Automatic}, DateTicksFormat -> {"MonthShort", "/", "YearShort"}]

No comments: