如何在整个系统中检查文件的给定路径是否存在 [英] how to check given path for file is exist or not in entire system

查看:65
本文介绍了如何在整个系统中检查文件的给定路径是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一些路径,比如programfiles\Test\test.xml。



我需要检查给定路径存在哪个驱动器。



例如,如果给定路径存在于C驱动器中,那么我需要返回C盘。



如何实现,C#中是否有任何功能可以实现这一点。

Hi All,

I have some path like "programfiles\Test\test.xml".

I need to check in which drive the given path exists.

for example if the given the path exists in "C" drive then i need to return C drive .

How to achieve,Is there any functionality in C# through which we can achieve this.

推荐答案

不 - 你必须手动完成,依次检查每个驱动器。



No - you would have to do it manually, by checking each drive in turn.

DriveInfo[] drives = DriveInfo.GetDrives();

将列出所有可用的,并且drives [n] .Name属性将为您提供C:\部分,以便您可以使用Path.Combine形成一个完整的测试路径。

Will list all those available to you, and the drives[n].Name property will give you the "C:\" part so you can use Path.Combine to form a complete path for testing.


这篇关于如何在整个系统中检查文件的给定路径是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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