C#-检查给定的URL是文件还是目录? [英] C# - Check if a given url is file or directory?

查看:253
本文介绍了C#-检查给定的URL是文件还是目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入http,ftp或本地路径的方法. 使用输入的URL,我需要确定它是文件还是目录.

I have a method which will input either a http , ftp or a local path. With the input url, i need to decide whether it is a file or directory.

Path.GetExtension(url)几乎可以正常工作.但是,如果目录以."开头/.以它的名称,那么此检查将失败.

Path.GetExtension(url) works almost fine. But if a directory begins with/have '.' in its name, then this checking will fail.

是否还有其他方法可以检查并列出目录中的url?

Is there any other methods to check and list url if directory ?

推荐答案

您可以使用File.Exists(url)Directory.Exists(url)

另一种方法是创建一个扩展数组,然后根据结果检查结果Path.GetExtension(url).

Another approach would be to create an array of extensions then check the result Path.GetExtension(url) against it.

这篇关于C#-检查给定的URL是文件还是目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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