Abhinav
Abhinav

Reputation: 1740

How to detect whether a zip/compressed file is completely unziped/uncompressed?

I have a java program to copy a folder(along with all files in it) from one location to another programatically.Now assume user pasted a zip file in this folder and then unzips it.Meanwhile my program starts,then it copies only the files which got unzipped in the folder.I want to wait till this unzipping of files is finished.

Hence I am looking for a programmatical way using which I can detect that the zip file has been completely uncompressed and then only resume with the normal copying of files.Is there any way to do this?

Upvotes: 0

Views: 1691

Answers (2)

Aaron Digulla
Aaron Digulla

Reputation: 328556

There is no reliable way to do this because you have no control over the unzipper; for example, the user could decide to unzip only some of the files. Since the unzipper won't tell you what the user selected in the UI, there is no reliable way to know when "all" files have been unpacked.

Workarounds:

  1. Users must unzip files in a different folder and then move the files into the folder that you watch. Move operations on the same disk are atomic, so this will make sure you get only complete files.

  2. Accept ZIP archives as input and unpack them yourself. That way, you have full control over the unpack process and can make sure you only process complete files. Also, since the ZIP "table of contents" is at the end of the ZIP archive, this will also make sure that you only process complete ZIP archives.

Upvotes: 0

OddBeck
OddBeck

Reputation: 845

See if you can rename the file that's beeing unpacked. If it's not "renamable" then the file is probably locked.

Upvotes: 1

Related Questions