perl- check size to see if file is complete
I'm trying to use perl to manipulate some files in a drop box environment. Everything is fine until someone drops a big (300+MB) file in the dropbox folder. It seems the script attempts to do its thing before the file is entirely copied into the dropbox. I was thinking of checking the file size every few seconds and when it came back three times the same size it could be assumed to be complete and press on. I've been trying to sort out lstat to do this but I can't seem to get my loops set up right. Basically, I want to do this:
glob the folder to an array
foreach each file
file size = $size
wait a few seconds
does file = $size?
repeat until file = $size three times
then continue processing file
go back to array grab next file and do it again.
Is my approach valid?
Any suggestions of perl script segments for each part of this game?
Thanks for helping a noob.
Do you have any control over the application dropping the files into the directory? We set up a process on a project here where each file being dropped had a zero byte flag file with it.
Basically what happened was this:
- Application writes data file (*.dat) to directory;
- After data file is written, application writes 0 byte flag file (*.flag) to directory.
The application polling the directory looks for the flag files. It's process is simple:
- Poll for flag files;
- Process the data file for each found flag file;
- Delete the data and flag file.
All of which is not much use if you can't control the application dropping the files into the directory...
Gilead's soln is good, used it myself in the past.
Otherwise a simple loop ?
|All times are GMT -5. The time now is 03:24 AM.|