我如何区分一拖一个文件或文件夹,并在C#中下降的事件吗? [英] How do I distinguish a file or a folder in a drag and drop event in c#?

查看:150
本文介绍了我如何区分一拖一个文件或文件夹,并在C#中下降的事件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有你将文件拖放到一个形式,我想知道我怎样才能使应用程序知道如果数据是一个文件或文件夹。

I have a form that you drag and drop files into and I was wondering how can I make the application know if the data is a file or a folder.

我的第一次尝试是寻找一个。在数据但某些文件夹确实有。在他们中。我也试着做了File.Exists和Directory.Exists条件,但随后只搜索当前应用程序的路径上,而不是其他地方。

My first attempt was to look for a "." in the data but then some folders do have a . in them. I've also tried doing a File.Exists and a Directory.Exists condition but then it only searches on the current application path and not anywhere else.

反正我有能以某种方式应用.Exists在一个特定的目录或有一个方法可以让我检查什么类型的数据拖入形式?

Is there anyway I can somehow apply the .Exists in a specific directory or is there a way I can check what type of data is dragged into the form?

推荐答案

由于路径作为一个字符串,可以使用有System.IO.File .GetAttributes(字符串路径)获得文件的属性的。

Given the path as a string, you can use System.IO.File.GetAttributes(string path) to get file's attributes.

FileAttributes attr = File.GetAttributes(path);
bool isFolder = (attr & FileAttributes.Directory) == FileAttributes.Directory;

这篇关于我如何区分一拖一个文件或文件夹,并在C#中下降的事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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