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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:42:57+00:00 2026-05-27T13:42:57+00:00

In C#, if I have a directory path and a relative file path with

  • 0

In C#, if I have a directory path and a relative file path with wildcard, e.g.

"c:\foo\bar" and "..\blah\*.cpp"

Is there a simple way to get the list of absolute file paths? e.g.

{ "c:\foo\blah\a.cpp", "c:\foo\blah\b.cpp" }

Background

There is a source code tree, where any directory can contain a build definition file. This file uses relative paths with wildcards to specify a list of source files. The task is to generate a list of absolute paths of all source files for each one of these build definition files.

  • 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-27T13:42:57+00:00Added an answer on May 27, 2026 at 1:42 pm

    You can get the absolute path first and then enumerate the files inside the directory matching the wildcard:

    // input
    string rootDir = @"c:\foo\bar"; 
    string originalPattern = @"..\blah\*.cpp";
    
    // Get directory and file parts of complete relative pattern
    string pattern = Path.GetFileName (originalPattern); 
    string relDir = originalPattern.Substring ( 0, originalPattern.Length - pattern.Length );
    // Get absolute path (root+relative)
    string absPath = Path.GetFullPath ( Path.Combine ( rootDir ,relDir ) );
    
    // Search files mathing the pattern
    string[] files = Directory.GetFiles ( absPath, pattern, SearchOption.TopDirectoryOnly );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a relative path (e.g. foo/bar/baz/quux.xml) and I want to pop a directory
I have some relative path in my *.vcxproj <ItemGroup> <ClCompile Include=myFile.cpp /> <ClCompile Include=..\..\Some\Reference\file.cpp
I have a base URL : http://my.server.com/folder/directory/sample And a relative one : ../../other/path How
I have a directory path stored in a text file, and I need to
I have a variable which has the directory path, along with the file name.
I have a file name logspath.txt which contain on the logs directory path on
I have an absolute path to file A. I have a relative path to
I was wondering if there is a way of making a relative path to
I want to get complete list of ftl file from directory and their subdirectory
Imagine I have a 'base' path object, denoting a directory, and a 'relative' path

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.