Solved

performing a function on all files in a drectory

Posted on 2003-11-07
5
189 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops 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.

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now