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

  • SEARCH
  • Home
  • 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 8058393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:20:33+00:00 2026-06-05T09:20:33+00:00

Suppose I have a folder called test . Now I pass that folder into

  • 0

Suppose I have a folder called test.
Now I pass that folder into a program and it will output a file called test.xyz in the same directory that contains the target folder.

The general logic I’m using is something like

string outDir = Path.GetDirectoryName(path);
string outName = Path.GetFileName(path).TrimEnd("\\".ToCharArray()) + ".xyz";
string outFile = Path.Combine(outDir, outName);

Which works, but it seems kind of excessive to perform so many operations just to build my new filename.

1: Can I reduce the number of Path calls to achieve my result?
2: Can I do something about the second line to avoid trimming and also avoid using that add operation?

  • 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-06-05T09:20:35+00:00Added an answer on June 5, 2026 at 9:20 am

    You could use a FileInfo for that!

    string path = @"C:\Windows\System32\";
    FileInfo fi = new FileInfo(path);
    string outFile = fi.DirectoryName + ".xyz";
    

    works like a charm. even with trailing slash in the directory string

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

Sidebar

Related Questions

Suppose I have a file test.c containing the following: // line 1 // line
Suppose we have a example.exe file. we first put that file in a new
I have a script that creates a folder called videos on a USB drive,
Suppose I have a bunch of files in a folder: foo.test.txt bar.txt ... And
Suppose I have programA (v1.0) folder with files abc.php, efg.php and hij.php. Now I
I have a program that contains a number of icons in an Icons folder
I have a file that users will purchase via paypal, clickbank and paydotcom. I
Suppose you have a full path to an accessible file or folder on the
Suppose I have an app that transfers files placed inside a main folder to
Lets suppose I have a list such as: [[BLAHBLAH\Desktop,BLAHBLAH\Documents,BLAHBLAH\Vids],[BLAHBLAH\Pics,BLAHBLAH\Folder,BLAHBLAH\Music]] And I wanted an output

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.