in reply to look for a file and send as a mail attachment by mail

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

  • Comment on Re: look for a file and send as a mail attachment by mail

Replies are listed 'Best First'.
Re^2: look for a file and send as a mail attachment by mail
by lukeyboy1 (Beadle) on May 31, 2006 at 09:04 UTC
    It sounds like you need to use File::List in order to get a list of files in the directory. Once you have this, then you can use the $msg->attach call any number of times to add the files to your message. Hope this helps: but File::List is really easy to use, and it won't require too much re-work of your script.