cc:

Heh...I wrote nearly that *exact* program a couple of years ago for work. I'd post it, except I wrote it in C#. Having said that, here are a couple of notes on your problems:

1) File not readable: I experienced the same thing. The problem is that the Windows app still had the file open. Once the file was closed, my app would read, send and delete it. It could also be permissions/ACL settings too. What I did here was to make a note of the file (push it onto an array), and try again on the next one-minute tick. Quite often, the file would be on the list for 15 minutes or so.

2) Need unique file names: Read the perldoc for File::Temp.... 8^).

3) Handle multiple files, but send only one mail per file: Turn your script into a subroutine, and call it once for each filename.

Regarding the code you posted: it looks like a good start, but one thing I'd change is that I'd not create so many subfolders, lest you make directory access incredibly slow after a while. (Many filesystems get slow if you have too many items in a directory.)

If you really need to segregate your files into subdirectories in a one-minute resolution, then you might want to split the hierarchy, like use YYYYMMDD/HHMM, so you'll only have 1440 items max in each YYYYMMDD directory.

Finally, you may want to check for the existence of the directory before calling mkdir so you don't die when you try to create a directory that already exists.

If you have any more questions, let us know!

--roboticus


In reply to Re: look for a file and send as a mail attachment by mail by roboticus
in thread look for a file and send as a mail attachment by mail by cc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.