最近在用qt写一个ui,遇到删除sd卡中的文件失败情况,有些时候是存在删除链表里面的文件在sd卡上已经不存在了,导致失败,以为我的链表是定时刷新的,但是文件是实时更新会同步覆盖的。这样就存在可能上一秒刚扫描存到链表里的文件下一秒就被循环覆盖了,所以增加文件判断机制。

在linux c中我一般同一用access去粗略的判断文件/目录是否存在。

QT中有以下方法可以用来判断文件/目录是否存在。

1、如果你确定自己需要判断的是一个文件则用以下接口

QFileInfo::isFile(QString fileName)方法

1 if(QFileInfo::isFile("fileName")
2   qDebug()<<"File exists";
3 else
4  qDebug()<<"File not exists";

2、如果你确定自己需要判断的是一个目录是否存在则用以下接口

QDir::exists(QString dir)方法

1  if(QDir::exists("dir")
2   qDebug()<<"Dir exists";
3 else
4   qDebug()<<"Dir not exists";

3、如果你不确定需要判断的是一个文件还是一个目录,你只想判断它是否存在,则用以下接口

QFile::exists(QString file)方法

QT判断文件/目录是否存在的更多相关文章

  1. Shell中判断文件,目录是否存在

    一. 具体每个选项对应的判断内容: -e filename 如果 filename存在,则为真 -d filename 如果 filename为目录,则为真 -f filename 如果 filena ...

  2. shell判断文件,目录是否存在或者具有权限

    shell判断文件,目录是否存在或者具有权限  #!/bin/sh  myPath="/var/log/httpd/"  myFile="/var /log/httpd/ ...

  3. php 判断文件/目录是否存的方法

    涉及函数 is_file(), is_dir() , file_exists() is_file() 判断文件是否存在 is_dir() 判断目录是否存在 file_exists() 既可用于判断文件 ...

  4. Python 判断文件/目录是否存在

    使用 os 模块 判断文件是否存在 os.path.isfile(path) 判断目录是否存在 os.path.isdir(path) 判断路径是否存在 # 使用 path 模块 os.path.ex ...

  5. shell判断文件,目录是否存在或者具有权限的代码

    核心代码 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/access.log" #这里的 ...

  6. shell判断文件,目录是否存在或者具有权限 (转载)

    转自:http://cqfish.blog.51cto.com/622299/187188 文章来源:http://hi.baidu.com/haigang/blog/item/e5f582262d6 ...

  7. linux shell判断文件,目录是否存在或者具有权限

    在linux中判断文件,目录是否存在或则具有的权限,根据最近的学习以及网上的资料,进行了以下的总结: #!/bin/sh myPath="/var/log/httpd/" myFi ...

  8. shell判断文件/目录是否存在

    https://www.cnblogs.com/37yan/p/6962563.html caution!!! if should be end with fi caution!!! there sh ...

  9. Qt 判断文件是否存在

    包含头文件:<QFileInfo> 代码: QFileInfo file("文件路径"); if(file.exists()==false){文件不存在:}

随机推荐

  1. Android系统编程入门系列之应用数据文件化保存

    应用中关于数据的持久化保存,不管是简单的SharedPreferences还是数据库SQLiteDatabase,本质上都是将数据保存到系统的某种类型的文件中.因此可以直接使用java.io.File ...

  2. 改Jupyter Notebook的默认工作路径?

    如何更改Jupyter Notebook的默认工作路径? 1.在cmd中输入命令使Jupyter产生配置文件:Jupyter_notebook_config.py jupyter notebook - ...

  3. 论文解读(PCL)《Prototypical Contrastive Learning of Unsupervised Representations》

    论文标题:Prototypical Contrastive Learning of Unsupervised Representations 论文方向:图像领域,提出原型对比学习,效果远超MoCo和S ...

  4. 【PHP】数组按照字母排序

    /** * 将数组按字母A-Z排序 * @return [type] [description] */ private function chartSort($list) { // $user=$th ...

  5. 执行:vim /etc/profile,提示:Command 'vim' not found, but can be installed with:

    root@uni-virtual-machine:/# vim /etc/profile Command 'vim' not found, but can be installed with: apt ...

  6. P5825-排列计数【EGF,NTT】

    正题 题目链接:https://www.luogu.com.cn/problem/P5825 题目大意 对于每个\(k\),求有多少个长度为\(n\)的排列有\(k\)个位置上升. \(1\leq n ...

  7. 在modal中的datetimepicker插件BUG修复

    前言:因为在模态框用到datetimepicker这一日期控件,而选中日期时,会触发模态框的再次打开,导致上面表单选的值会重新加载 解决办法: 用stopPropagation() 方法阻止事件传播, ...

  8. spring-data-redis 上百万的 QPS 压力太大连接失败,我 TM 人傻了

    大家好,我们最近业务量暴涨,导致我最近一直 TM 人傻了.前几天晚上,发现由于业务压力激增,某个核心微服务新扩容起来的几个实例,在不同程度上,出现了 Redis 连接失败的异常: org.spring ...

  9. 踩坑系列《四》a标签的href属性拼接问题

    如上所示,无法直接在 html里面的 a 标签的href属性传递参数时,只需要在 JS 中获取对应 a 标签的id,再通过 attr 方法抓到 href,进行字符串拼接即可

  10. MYSQL小版本升级(5.7.21至5.7.25)

    1.环境确认 [root@mysql ~]# ps -ef |grep -i mysql root 9173 1 0 2020 ? 00:00:00 /bin/sh /mysql/data/mysql ...