Solved

performing a function on all files in a drectory

Posted on 2003-11-07
5
195 Views
Last Modified: 2010-04-15
i've got an api that takes in either a file name or a directory name and calls a function.  i use GetFileAttributes to find out if what is passed in is a file or directory.  for a file i just pass it on to the function, but if a directory is passed, i need to write something that will recursively pass each file from that directory to my funtion until all files have been preoccessed.  i need a code example for a little help since i've been coding in VB for the past few months, my C programming is really rusty.  i was thinking i'd need to use findfirstfile and findnextfile somewhere.  thanks for the help

Kris
0
Comment
Question by:kris-mayco
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 9702052
yes, use ResultSetMetaData Class:

ResultSetMetaData rsmd = rs.getMetaData();
System.out.println(rsmd.getColumnDisplaySize(<int column>));
0
 
LVL 45

Accepted Solution

by:
Kent Olsen earned 100 total points
ID: 9702889

findfirst() is not recursive so when you're scanning a directory's contents, call it on a subdirectory voids the ability to scan the rest of the parent directory.

In "metacode", here's what the function to recursively scan all subdirectories will look like:


ScanDirectory (char *BasePath)
{
  char **Subdirs;    /* Table of subdirectories  */
  int   SubdirCount = 0;
  int   idx;
  char *path;

  path = findfirst (BasePath);
  while (path)
  {
    if (isdirectory (path))
    {
      Subdirs = AddPathToTable (Subdirs, SubdirCount, path);
      SubdirCount++;
    }
    else
      ProcessFile (path);
    path = findnext ();
  }

//  Now process all of the subdirs
  for (idx = 0; idx < SubdirCount; SubdirCount++)
  {
    path = BuildPathName (Subdirs[idx]);
    ScanDirecotry (path);
  }
}


Good Luck!
Kent
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 9702910
oops, sorry, my comment above was obviously posted in the wrong thread ;)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question