reading images from a directory while copying images into the same directory

Hao Zhou Source

I need to do such works just like the title means.I need to check continuously where there are pictures under a specified directory,and read them to do some necessarily process. But the same time someone else may copy images into the same directory. What should I do to avoid reading incomplete images? Thanks very much. I'm using C.But any language is OK. I just need an idea. I'm wondering if it's possible to judge whether it's a complete image?



answered 6 days ago Tom's #1

Under Linux, there are the guarantee that moving a file in the same device is an atomic operation. That means that either the file doesn't exist, or the file is complete. More info in the man of rename(2) : look at the "EXDEV" error.

If you can't make this, I advise to create a special dir in your target dir (nommed "tmp" ?), copying into the special dir and after move thie file from the special dir to the target dir.

Under Windows, I think there is the same guarantee, but I'm not really sure.

comments powered by Disqus