duanhuo0577 2014-10-02 19:09
浏览 401

File_exists()在返回true时返回false,是什么导致这个?

I edited the entire question to better represent the answer.

I had a for loop which would access and edit image files. Within the loop a file_exists() check was made. If the image file did not exist a blank one would be created.

What was happening was that even after the file was created, the file_exists() would continue returning false and creating new blank files (overwriting the previous operations).

This happens because file_exists() and some other file functions caches the result. To prevent this, use clearstatcache(); before using these functions if you expect the result to have changed and are checking the same file!

  • 写回答

1条回答 默认 最新

  • doushichi3678 2014-10-07 15:34
    关注

    After further investigating, I discovered the reason why some of my images were disappearing: the function file_exists() caches the result.

    When looping through the same files many times, if the file did not exist to start for, then file_exists() would return false and a blank file would be created.

    If this same file was used again and the result "false" was cached, then the previous image would be destroyed and a new blank file used.

    To prevent this, I inserted clearstatcache(); at the start of very loop. This solved my problems!

    I am changing the question title to better represent this situation.

    评论

报告相同问题?

悬赏问题

  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题