如何区分c#中的拖放事件中的文件或文件夹? [英] How do I distinguish a file or a folder in a drag and drop event in c#?
问题描述
我第一次尝试寻找一个。在数据中,但是一些文件夹确实有一个。在他们中。我也试过做一个File.Exists和一个Directory.Exists条件,但是它只搜索当前的应用程序路径,而不是其他任何地方。
有没有吗可以以某种方式将.Exists应用到特定的目录中,或者有什么方法可以检查什么类型的数据被拖入表单?
将路径作为字符串,您可以使用 System.IO.File.GetAttributes(string path)获取文件的属性。
FileAttributes attr = File.GetAttributes(path);
bool isFolder =(attr& FileAttributes.Directory)== FileAttributes.Directory;
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.
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.
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?
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屋!