本文介绍了如何读取动态更改其名称的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在目录中有一个文件夹。

例如: D:\ Main \Folder1.0 \ Test.txt

如果我使用此路径访问该文件然后我能够阅读。但有时 Folder1.0 变成 Folder1.2 (由于逻辑上有些更新)等等。

所以新的路径将会如:

D:\ Main \Folder1.2 \ Test.txt



如何请阅读此文件,请建议。

提前致谢。



我尝试过:



我的方法是放一些像Folder *之类的通配符。但不确定如何实现这一点。

I have one folder in a directory.
For example: D:\Main\Folder1.0\Test.txt
If i use this path to access that file then i am able to read. But after sometimes that Folder1.0 becomes Folder1.2 (due to some updation with logic) and so on.
So the new path will be like:
D:\Main\Folder1.2\Test.txt

How to read this file please suggest.
Thanks in advance.

What I have tried:

My approach is to put some wildcard characters like "Folder*" or something. But not sure how to implement this.

推荐答案

string[] folders = Directory.GetDirectories(@"D:\Main\", "Folder*");
string finalPath = folders[0] + @"\Test.txt" //if it gurantees that there will be only one folder or you can put additional logic
string finalPath=



你可以使用 []



希望,有帮助:)


You can aslo use Directory.EnumerateDirectories Method (String, String) (System.IO)[^]

Hope, it helps :)


这篇关于如何读取动态更改其名称的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 05:24