有什么建议如何检测文件? [英] Any suggestions how to detect file?

查看:77
本文介绍了有什么建议如何检测文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 abc =label_me_red.ico.deploy是来自StreamReader.ReadLine()的字符串

if(File.Exists(label_me_red.ico.deploy))
{
//文件
}
其他
{
//文件夹
}



问题是它没有检测到文件,它转到其他条件并显示为目录。

解决方案

它只是意味着该文件不存在。 />


那么你应该理解这一点:这样的文件命名表明它位于工作目录中。这个目录可以是一个可执行文件目录,但它绝对可以是任何东西。你知道吗到工作目录完全取决于用户如何启动应用程序,可以在任何地方,除非你的程序修改它。



请查看我过去的答案目录信息:

如何找到我的程序目录可执行目录),

如何查找我的程序目录当前目录,特殊文件夹



没有硬编码文件路径可以的情况有用。



-SA


if(File.contains(。)

{

// file。

}

abc = "label_me_red.ico.deploy" is string from StreamReader.ReadLine()

if(File.Exists("label_me_red.ico.deploy"))
{
   // File
}
else
{
// Folder
}


Problem is Its not detecting as File, its going to else condition and displaying as directory.

解决方案

It simply means that the file does not exist.

By the way, you should understand this: such naming of a file suggests that it is located in the working directory. This directory can be an executable file directory, but it can be absolutely anything. Do you know that to working directory totally depends on how the user starts the application and can be anywhere, unless your program modifies it.

Please see my past answer for comprehensive information on directories:
How to find my programs directory ( executable directory),
How to find my programs directory (current directory, "special folders").

There are no situations where a hard-coded file path can be useful.

—SA


if(File.contains(".")
{
//file.
}


这篇关于有什么建议如何检测文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆