Solved

performing a function on all files in a drectory

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
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.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

920 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

16 Experts available now in Live!

Get 1:1 Help Now