• Post Reply Bookmark Topic Watch Topic
  • New Topic

check if file creation or transfer is complete  RSS feed

 
manish ahuja
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I wanted to check if there is a way to figure out a file inside a directory is complete and not partial i.e in the process of being generated. There is an external process which transfers the file to a certain directory. Another process periodically checks the directory for files and reads it when it finds a new one. I don't want the read process to start reading while the file transfer process is still underway.

Is there a way to detect if a file transfer process was complete.


Let me know your thoughts.

Thanks.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a guess:

Check the file size, wait a couple of seconds, check the file size again. If it is the same; done.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That won't work properly if the writing (temporarily) hangs for whatever reason.
 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The short answer to the question is "No".

The usual solution (for those who require some sort of reliable solution) is for the application which is producing the file to send some kind of explicit signal saying it's complete. For example moving the completed file into some other directory, or changing its name to something which the receiver is looking for, or creating another file (this one empty) with a related filename.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder if the canWrite() will return false if the file is being written to by another application? Too early for me to put together a test code. Maybe later.
 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very unlikely. In non-Windows environments you can even delete a file which is being written to by another application.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!