Help re deleting files please?

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

On Nov 29, 2006, at 3:05 PM, Greg H. wrote:

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.

I thought you were considering using Ruby for this task. :wink:

Seriously, why don’t you give it a shot and give us a shout at any
point you get stuck on. Send us the broken code and we will gladly
help you over the hump. You will learn a lot more that way and may
even surprise yourself.

James Edward G. II

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) }

wow - one line - thanks heaps - gives me some pointers re where to dive
into
the API doco/classes - take your points
thanks