开发者

Detecting overwrites when using unzip from command line in Redhat

Possibly this should be on Superuser, but I'm using it in code so thought I'd start here.

My C++ program unzips a .gz file using the "system()" call. (Yes I know it's taboo, but it was the best of a bad lot when I started this project a while back, and I asked Unzipping a file from C++ on Redhat: alternatives to system() when I thought I'd have the chance to improve it, but I haven't managed to implement anything yet)

As there is a chance that a file with the same name already exists, the unzip call uses the "-o" modifier to for an over-write.

Is there a way to detect that there has been an overwrite? I 开发者_C百科am open to alternatives to system() and unzip.


OS: Redhat

Language: C++

IDE: Eclipse


I believe the obvious answer would be to try to detect whether there is a file with the appropriate name on disk before you even run the system command; if a file exists prior to unzipping, then an overwrite will occur. You can easily check whether a file exists by fopening it with a mode of "r" and checking the return value for a valid file handle. (Don't forget to fclose the file if it does already exist.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜