From: Hung Dao Date: 2006-11-30T19:54:38+09:00 Subject: Re: help re deleting files please? ------=_Part_39097_17086348.1164884074381 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline This smells like a homework , by the way , the best approach to Ruby is practice by coding yourself then post the code for others to check or optimize Hope this piece of code helps you somehow Dir.foreach("./") {|x| File.delete(x) if (File.size(x) <7*1024)&&(File.size(x) >5*1024) } On 11/29/06, Greg Hauptmann wrote: > > Hi, > > I have a small task which I was considering using ruby for - if anyone has > a > minute and could quickly type in the ruby code (assuming its a few lines) > that would be fantastic. The spec is: > > Input > > - Small ruby program needs to be triggered by a windows batch file ( > i.e. called out from within a windows batch file) > - The batch file will be provided (from the program that kicks it off) > with a variable containing a filename > > Processing > > - Take the filename as input > - To search for files under a given directory (so in including > sub-directories) and delete any files which match the conditions: > - (size < 7kb) AND (size > 5kb) > - file is closed (i.e. don't want to pick up a file currently > being written to by the program which may be just starting to grow) > - Optionally (not sure yet) - May want to limit the files to > those which match a wildcard version of the filename which was > provided by the batch file (e.g. if filename was " > thisfile-v22.mpg", may want to filter on only files matching " > thisfile*" if that makes sense. > > Output > > - No real output required, however if it was simple a log file which > was appended to with Date/Time, FileDeleted may be nice > > > Thanks in advance > Greg > > ------=_Part_39097_17086348.1164884074381--