Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

performing a function on all files in a drectory

Posted on 2003-11-07
5
Medium Priority
?
197 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 46

Accepted Solution

by:
Kent Olsen earned 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
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…
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 while-loops in the C programming language.

721 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