Replace words dynamically

Asked

Viewed 71 times

3

For example, I have file addresses:

C:/windows/x.exe

C:/windwos/system32/example.exe

I would like to replace the file name and extension with "", so:

C:/Windows/

C:/windows/system32/

  • 1

    This address would be stored in a String ?

  • 1

    I’m doing a search and throwing the results in a var: var Subfile = Directory.Getfiles(path, "*. csproj", Chopseartion.Alldirectories);

1 answer

6


You can use the method Path.Getdirectoryname

var path1 = @"C:/windows/x.exe";
var path2 = @"C:/windwos/system32/exemplo.exe";
Console.WriteLine(Path.GetDirectoryName(path1) + Path.DirectorySeparatorChar);
Console.WriteLine(Path.GetDirectoryName(path2) + Path.DirectorySeparatorChar);

Dotnetfiddle

Browser other questions tagged

You are not signed in. Login or sign up in order to post.