6、FileInfo Exists

2023-10-16 14:48
文章标签 exists fileinfo

本文主要是介绍6、FileInfo Exists,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

前言:System.IO下面的FileInfo类,继承至FileSystemInfo,是用来对系统中的文件进行创建、复制、删除等操作,Exists属性是对文件的判断,不是对文件夹的判断,这个很重要,不然可能会对需求做出错误的判断;

原文注释

        //// 摘要://     Gets a value indicating whether a file exists.//// 返回结果://     true if the file exists; false if the file does not exist or if the file is a//     directory.public override bool Exists { get; }

看到没,file exists,是file,即视频、文档等文件,不是Directory。

代码

        /// </summary>/// <param name="path"></param>/// <returns></returns>public static int GetFileSize(string path){FileInfo fileInfo;try{fileInfo = new FileInfo(path);}catch{return 0;}if (fileInfo != null && fileInfo.Exists){return (int)Math.Ceiling(fileInfo.Length / 1024.0);}else{return 0;}  }

结果

path=F:\Doc\工作中疑问.txt,具体的文件

 path=F:\Doc,文件夹

这篇关于6、FileInfo Exists的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/220223

相关文章

in 和 exists 的比较

EXISTS的执行流程      select * from t1 where exists ( select null from t2 where y = x ) 可以理解为:   for x in ( select * from t1 )   loop       if ( exists ( select null from t2 where y = x.x )       the

git pull失败提示fatal: Unable to create 'E:/job/tpaas-web/.git/index.lock': File exists.

git 提交时失败   提示如下错误:fatal: Unable to create 'E:/job/tpaas-web/.git/index.lock': File exists.   解决方法:删除.lock文件       rm -f ./.git/index.lock 命令执行后再次pull

SQL—EXISTS的用法(转)

比如在Northwind数据库中有一个查询为 SELECT c.CustomerId,CompanyName FROM Customers cWHERE EXISTS(SELECT OrderID FROM Orders o WHERE o.CustomerID=c.CustomerID) 这里面的EXISTS是如何运作呢?子查询返回的是OrderId字段,可是外面的查询要找的是Cust

MP条件构造器之常用功能详解(or、and、exists、notExists)

文章目录 or使用范围方法签名参数说明示例使用 `or` 改变查询条件的连接方式为 OR动态根据条件改变查询条件的连接方式为 OR使用 `or(Consumer<Param> consumer)` 添加 OR 嵌套条件动态根据条件添加 OR 嵌套条件 and使用范围方法签名参数说明示例动态根据条件添加 AND 嵌套条件 exists使用范围方法签名参数说明示例动态根据条件添加 EXIST

mysl 常用函数 union all if ifnull exists case when

mysl 常用函数 union all if ifnull exists case when 1.union all UNION 操作符用于合并两个或多个 SELECT 语句的结果集。请注意,UNION 内部的 SELECT 语句必须拥有相同数量的列。列也必须拥有相似的数据类型。同时,每条 SELECT 语句中的列的顺序必须相同。 默认地,UNION 操作符选取不同的值。如果允许重复的

MySQL——多表操作(四)(2)带 EXISTS 关键字的子查询

EXISTS 关键字后面的参数可以是任意一个子查询,这个子查询的作用相当于测试,坏产生任何数据,只返回 TRUE 或 FALSE,当返回值为 TRUE 时,外层查询才会执行。         例如,查询 employee 表中是否存在年龄大于 21岁的员工,如果存在,则查询 department 表中的所有记录,SQL 语句如下: SELECT * FROM departme

PostgreSQL DETAIL: Key (id)=(423) already exists. 问题解决

一、问题 发现一些写入数据请求报错: File "/.env/python/dist-packages/sqlalchemy/dialects/postgresql/asyncpg.py", line 550, in _prepare_and_executeself._handle_exception(error)File "/.env/python/dist-packages/sqlalch

springboot项目运行在docker中 file.exists()返回false没有报错

springboot项目运行在docker中 file.exists()返回false没有报错 原文链接:http://www.lskyf.com/view/31 表现:在windows运行正确,但是打包后运行在docker容器中找不到文件 思考1:路径不对。 经检查路径后被排除   思考2:写法不对。 网上有云:"windows 是/,linux应该是\\",经过检查路径后被排除

sql中exists和not exists用法

之所以要说这个问题,是因为项目中用到了not exists,但两者写的语句只有一点差别,结果一个有问题了,一个没问题。具体问题下面详细说明,先来看看exists如何应用。 exists:         强调的是是否有返回集,不需知道具体返回的是什么,比如:          SELECT*FROMcustomerWHEREnot EXISTS (SEL

1z0-071 Oracle Database 12c SQL 第19题 exists语句

Q19.Which two statements are true regarding the EXISTS operator used in the correlated subqueries? (Choose two.) A. The outer query stops evaluating the result set of the inner query when the first