Solved

Process 50 files in one folder a file at a time thru a dialog editbox using VC++ 6.0

Posted on 2002-03-12
6
209 Views
Last Modified: 2010-04-01
I wrote a program to process a file at a time thru the edit box by selecting the file from the folder.  Now I need to modify the program so that I can process up to 60 files in a directory and run them thru the program that I wrote using VC++ 6.0 or by using wildcards for the file names.  Is there a way that I can do this? and if there is could your provide the sample code to do this?  
0
Comment
Question by:adatd
6 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 6858866
What type of program do you write? (Dialog based, Doc/View, Console)

>>Is there a way that I can do this?
Yes.

>>and if there is could your provide the sample code to do
>>this?  

What method do you prefer?  Do you want the user to select the files from a Common dialog?
Or do you want the wildcard approach?
0
 
LVL 6

Expert Comment

by:thienpnguyen
ID: 6858883
You can use _findfirst, _findnext ...

* FFIND.C: This program uses the 32-bit _find functions to print
 * a list of all files (and their attributes) with a .C extension
 * in the current directory.
 */

#include <stdio.h>
#include <io.h>
#include <time.h>

void main( void )
{
    struct _finddata_t c_file;
    long hFile;

    /* Find first .c file in current directory */
    if( (hFile = _findfirst( "*.c", &c_file )) == -1L )
       printf( "No *.c files in current directory!\n" );
   else
   {
            printf( "Listing of .c files\n\n" );
            printf( "\nRDO HID SYS ARC  FILE         DATE %25c SIZE\n", ' ' );
            printf( "--- --- --- ---  ----         ---- %25c ----\n", ' ' );
            printf( ( c_file.attrib & _A_RDONLY ) ? " Y  " : " N  " );
            printf( ( c_file.attrib & _A_SYSTEM ) ? " Y  " : " N  " );
            printf( ( c_file.attrib & _A_HIDDEN ) ? " Y  " : " N  " );
            printf( ( c_file.attrib & _A_ARCH )   ? " Y  " : " N  " );
            printf( " %-12s %.24s  %9ld\n",
               c_file.name, ctime( &( c_file.time_write ) ), c_file.size );

            /* Find the rest of the .c files */
            while( _findnext( hFile, &c_file ) == 0 )
            {
                printf( ( c_file.attrib & _A_RDONLY ) ? " Y  " : " N  " );
                printf( ( c_file.attrib & _A_SYSTEM ) ? " Y  " : " N  " );
                printf( ( c_file.attrib & _A_HIDDEN ) ? " Y  " : " N  " );
                printf( ( c_file.attrib & _A_ARCH )   ? " Y  " : " N  " );
                printf( " %-12s %.24s  %9ld\n",
                   c_file.name, ctime( &( c_file.time_write ) ), c_file.size );
            }

       _findclose( hFile );
   }
}

0
 
LVL 6

Expert Comment

by:thienpnguyen
ID: 6858897
0
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.

 
LVL 4

Accepted Solution

by:
pagladasu earned 250 total points
ID: 6858935
WIN32_FIND_DATA filedata;
char *filename;
HANDLE handle=FindFirstFile("*.txt",&filedata);
if handle{
  do{
    filename = filedata.cFileName;
    //call your processing routine for filename here
    BOOL ret=FindNextFile(handle,&filedata);
  }while(ret);
}
0
 

Author Comment

by:adatd
ID: 6859949
It is a a Dialog based program and I would rather use the wildcard approach by entering the directory in the edit box ie...   "c:\morethings\jackson\*.050"

that way it can go to that directory and process all the files in it that match the .050 extension.
0
 
LVL 3

Expert Comment

by:ruff_ryder
ID: 6860601
Use a common dialog as Axter suggested. With the Common dialog you can apply the filter where only files with a specific extension will be shown in the File Open Dialog that is displayed.

This way users can choose from only files with the .050 extension you specify.

Have a look at the CFileDialog class in the MSDN docs.
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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

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