Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 685279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:54:23+00:00 2026-05-14T01:54:23+00:00

System.IO.Path in .NET is notoriously clumsy to work with. In my various projects I

  • 0

System.IO.Path in .NET is notoriously clumsy to work with. In my various projects I keep encountering the same usage scenarios which require repetitive, verbose and thus error-prone code snippets that use Path.Combine, Path.GetFileName, Path.GetDirectoryName, String.Format, etc. Scenarios like:

  • changing the extension for a given file name
  • changing the directory path for a given file name
  • building a file path using string formatting (like “Package{0}.zip“)
  • building a path without resorting to using hard-coded directory delimiters like \ (since they don’t work on Linux on Mono)
  • etc etc

Before starting to write my own PathBuilder class or something similar: is there a good (and proven) open-source implementation of such a thing in C#?

UPDATE: OK, just an illustration of what I mean:

        string zipFileName = Path.GetFileNameWithoutExtension(directoryName) + ".zip";
        zipFileName = Path.Combine(
            Path.GetDirectoryName(directoryName), 
            zipFileName);

A nicer fluent API could look like this:

Path2 directoryName = "something";
Path2 zipFileName = directoryName.Extension("zip");

Or when building a path:

Path2 directoryName = "something";
Path2 directory2 = directoryName.Add("subdirectory")
    .Add("Temp").Add("myzip.zip");

instead of

string directory2 = Path.Combine(Path.Combine(Path.Combine(
     directoryName, "subdirectory"), "Temp"), "myzip.zip");

I actually did implement something like this in the past, but in a separate project. I’ve decided now to reuse it as a standalone C# class added “as link” in VisualStudio in my other projects. It’s not a cleanest solution, but I guess it will do. If you’re interested, you can see the code here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:54:23+00:00Added an answer on May 14, 2026 at 1:54 am

    You might also want to checkout the “NDepend.Helpers.FileDirectoryPath” library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The .NET Framework defines a System.IO.Path.GetTempFileName method, which guarantees that the temporary filename it
I have an asp.net app that uses System.IO.Path.GetTempFileName() for temporary files. In the production
What's the path on disk used by System.Net.WebClient (i.e. WebRequest ) etc. to cache
I have system path vickey@tb:~/work/sayonara$ echo $PATH /usr/local/Trolltech/Qt-4.8.0/bin:/home/vickey/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/vickey/bin:/home/vickey/tunebasket/p2p/ vickey@tb:~/work/sayonara$ cd /usr/local/ I want to
System.Reflection.Assembly.Load(System.IO.File.ReadAllBytes(path)) So this is a work around to not being able to use T4
In the .NET base class library there is a class System.IO.Path for doing common
I have the following LINQ query: List<string> Types = (List<string>)Directory.GetFiles(@C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727) .Where(x => System.IO.Path.GetFileNameWithoutExtension(x).Contains(Microsoft)) .ToList<string>();
I want to check that a file system path is valid and safe to
I want to change the build system path for building my VC++ project in
I've seen several suggestions on naming files randomly, including using System.IO.Path.GetRandomFileName() or using a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.