Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-11-2008, 02:50 PM   #1
Registered: Jan 2007
Location: Dallas, Oregon
Distribution: Ubuntu; Knoppix; DSL; Raspbian
Posts: 30

Rep: Reputation: 0
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.
Old 02-11-2008, 04:17 PM   #2
Senior Member
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 165Reputation: 165
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...
Old 02-13-2008, 06:20 PM   #3
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,396

Rep: Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395
Gilead's soln is good, used it myself in the past.
Otherwise a simple loop ?

for $file ( @file_list )
    $last_size = (stat($file))[7];
        $curr_size = (stat($file))[7];
        if( $curr_size == $last_size )
            if( $cnt >= 3 )
        $last_size = $curr_size;
    $last_size = 0;
    $curr_size = 0;
    $cnt = 0;
NB: Untested (!) but you get the idea ...


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl: Check if file has been created in the last 10 minutes introuble Programming 2 06-02-2006 10:58 AM
is there a way to increase a partition size after the installation is complete? tad@optix Red Hat 6 06-13-2005 06:33 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
SuSE 8.1 ftp complete directory tree size? cav Linux - General 2 04-01-2003 12:44 PM
Need script to check file size. _TK_ Linux - General 1 08-06-2001 08:30 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:43 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration