Click here to Skip to main content
15,894,291 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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.
Posted
Updated 21-Sep-16 19:28pm
v2
Comments
Karthik_Mahalingam 22-Sep-16 1:12am    
what about Folder1.0 ?
will it be still present ?
Jiban jyoti Rana 22-Sep-16 1:13am    
No the new folder will replace the old one.
Jiban jyoti Rana 22-Sep-16 3:41am    
Directly in File Path can we use the wildcard character to access that folder? i.e: Without using this Get Directory Method.

1 solution

You can make use of Directory.GetDirectories Method (String, String) (System.IO)[^] to get the folder name and then construct the final path.

Something like following-
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 :)
 
Share this answer
 
v4
Comments
Karthik_Mahalingam 22-Sep-16 2:08am    
Hi SSG, seems little correction to be made on your code.
Suvendu Shekhar Giri 22-Sep-16 2:21am    
Yes. Can you please suggest?
Karthik_Mahalingam 22-Sep-16 2:31am    
string finalPath= folders[0]+"\\Test.txt";
Suvendu Shekhar Giri 22-Sep-16 2:43am    
Yes. Correct. Thanks a lot for the suggestion :)
Karthik_Mahalingam 22-Sep-16 2:45am    
:) you shall update in the solution as well, it might help someone in future.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900