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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:01:39+00:00 2026-05-11T02:01:39+00:00

I was given this code a while back. I finally got around to testing

  • 0

I was given this code a while back. I finally got around to testing it (with some changes to put the files in a different place)…

void AddFiles(AnsiString path/*, TDataSet *DataSet*/) { TSearchRec sr; int f;     f = FindFirst(path+'\\*.*', faAnyFile, sr);     while( !f )     {         if(sr.Attr & faDirectory)         {                 if(sr.Name != '.'   &&   sr.Name != '..')                 {                         path.sprintf('%s%s%s', path, '\\', sr.Name);                         AddFiles(path/*, DataSet*/);                 }         }         else         {                 Form1->ListBox1->Items->Add(path+ '\\'+ sr.Name);                 //DataSet->Append();                 //DataSet->FieldByName('Name')->Value = sr.Name;                 /* other fields ... */                 //DataSet->Post();         }         f = FindNext(sr);     }     FindClose(sr); } 

It doesn’t work properly. In the beginning it gets mixed up..

a real structure of…

root root\subdir1 root\subdir2 root\subdir3

gets messed up like this…

root root\subdir1 root\subdir1\subdir2 root\subdir1\subdir2\subdir3

and eventually it stops including the root or sub\sub folders and ‘path’ just contains a subfolder (without its root folders)

this is completely useless for aquring useable full-path filenames.

so either can you tell me where the code is going wrong… or give me some advice on how to get the full path filenames in a dir and all its subdirs.

I want it to be as basic as possible. i.e. no uncommon advanced c++ features. stuff that a builder noob is likely to be able to debug.

  • 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. 2026-05-11T02:01:39+00:00Added an answer on May 11, 2026 at 2:01 am

    Here you append each subpath to the current path:

    path.sprintf('%s%s%s', path, '\\', sr.Name); AddFiles(path/*, DataSet*/); 

    Use a new variable for the combined path, so you don’t mess up the path variable you still need for the rest of the files/dirs in the directory:

    AnsiString subpath; subpath.sprintf('%s%s%s', path, '\\', sr.Name); AddFiles(subpath/*, DataSet*/); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 70k
  • Answers 70k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer My advice - don't do it. Only even consider 3.0… May 11, 2026 at 12:54 pm
  • added an answer There is no single answer, it depends on your scenario,… May 11, 2026 at 12:54 pm
  • added an answer This is a standard shortest path problem. There are lots… May 11, 2026 at 12:54 pm

Related Questions

I was once given this task to do in an RDBMS: Given tables customer,
I posted this question: https://stackoverflow.com/questions/418597/java-and-net-for-php-programmer and the answers I was given didn't really help
In this question , I was given a really cool answer to alternating an
I was given a C++ project that was compiled using MS Visual Studio .net
Given a columns' index, how can you get an Excel column name? The problem
I have a project here that connects to an in-production database and grabs tables
Let's say I have a javascript method that takes a little to long to
Back in the old days, Help was not trivial but possible: generate some funky

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.