Solved

performing a function on all files in a drectory

Posted on 2003-11-07
5
192 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
  • 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:
Kdo 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Picking random number 8 177
Why this code doesn't work? 8 101
Compile VxWorks Toronado project under Visual Studio 11 200
How to create frequencies of a variable from SAS dataset? 10 125
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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

803 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