Reputation: 1929
I need to replace the directory structure or the file-path from the file name with whitespace.
Input text :
D:\LIGHTNING_ProductSecurity\BACKEND\CORE\dal\src\main\java\com\adminserver\dal\AuthPlanDal.java
Output text :
D:\LIGHTNING_ProductSecurity\BACKEND\CORE\dal\src\main\java\com\adminserver\dal\
How can it be done?
Upvotes: 0
Views: 131
Reputation: 1458
this might help:
string path = @"D:\LIGHTNING_ProductSecurity\BACKEND\CORE\dal\src\main\java\com\adminserver\dal\AuthPlanDal.java";
string fullPathWithoutFilename = Path.GetFullPath(path).Replace(Path.GetFileName(path), "");
Upvotes: 0
Reputation: 39355
Use this regex for search, and replace with empty.
(?<=\\)[^\\]+$
This one is matching the last portion(i.e. AuthPlanDal.java
) after the \
from the file path.
Anyone can try this at online.
Upvotes: 0