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 8240457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:29:57+00:00 2026-06-07T20:29:57+00:00

I am trying to extract the directory from a path that may or may

  • 0

I am trying to extract the directory from a path that may or may not contain the file name. The problem is that when I am trying to get the directory name of a path that is already a directory, the Path.GetDirectoryName() returns the upper level of that dir. The path is loaded from the database so I cannot check the file attributes.

Ex.
Path.GetDirectoryName(“D:\Work\Project\Sources\trunk\Project2\bin\Debug”) returns “D:\Work\Project\Sources\trunk\Project2\bin\”

I was thinking of a simple algorithm, that checks if the path contains the “.” character; if yes, then we are dealing with a path that contains the file name. Unfortunately the directory names can also contain the “.” character.

I know that there is no perfect solution for this issue but what is the next best thing?

There is already a Stackoverflow question about the issue but it assumes that the file or directory already exists.

  • 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-07T20:29:58+00:00Added an answer on June 7, 2026 at 8:29 pm

    If your directory or file doesn’t exist, there is no way to know if it’s a file or a directory.

    In your example D:\Work\Project\Sources\trunk\Project2\bin\Debug, there could be a file named Debug (without extension) in the bin directory.

    Another example: D:\Work\Project\Sources\trunk\Project2\bin\Debug\file.exe, there could be a directory named file.exe which is a sub-dir of Debug…

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

Sidebar

Related Questions

im trying to extract some files from a jar-file downloaded using java-webstart. below code
I am trying to extract the page name from a complex url. This post
I'm trying to extract all the unique characters from my utf-8 French dictionary file
I'm trying to extract the urls from a .htm source, that contains 3 other
I'm trying to write a function in C# that gets a directory path as
I am trying to create a text file of the path and file name
I am trying to extract icons images from specific files or directory using Java.
This may be a simple question...I'm trying to extract or unzip exe file. I
I'm trying to get the cxf-codegen-plugin to generate sources from my wsdl file. When
I'm trying to create a program that extracts the metadata from an image file.

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.