Thread: Showing the *.* files

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Showing the *.* files

    I'm writing a win32 console program and I must have a function which displays the *.lng files. Now, when I was writing for DOS there were a ffblk structure, function findfirst and findnext in "dir.h" library for this purpose, but now I'm writing in Windows and I don't know what function am I supposed to use.

    Please help.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I think the windows versions work about the same and are named similarly, ie:

    FindFirst(), et al....

    But the DOS ones work fine too in Windows.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    DOS ones are not working. At least ffblk structure. Is there any similar structure in windows?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Not that I know of...

    Does it work in DOS mode for you?

    If not, post your code.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    your going to hate me for this
    (it works on Linux but it might work on Win32 or DOS)
    Code:
    #include <stdio.h>
    int main()
    {
    	system("dir *.exe");
    	printf("\n");
    	return 0;
    }
    // replace *.exe with *.extension or whatever you want, it still works.
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  6. #6
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    This code was compiled with Turbo C++ 3.0 and it is working. But if I compile this with VC++ 6.0 it is not working. The error that is reported is that the compiler can't find the "dir.h" library.

    Code:
    # include <dir.h>
    
    void ShowLNGFiles() 
    {
       struct ffblk File01;
       int Search = 0;
    
       Search = findfirst ("*.lng", &File01, 0);
       while (!Search)
       {
          printf("\n%s", File01.ff_name);
          Search = findnext (&File01);
       }
    }
    Now I just need the replacement for this function, so that will work in win32 console program (compiled with VC++ 6.0).

    EDIT:
    Lynux: Thanks, but no thanks. I'm not looking for that kind of solution.
    Last edited by GaPe; 04-27-2002 at 12:05 PM.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  7. #7
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    its in io.h in MSVC
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  8. #8
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Thanks no-one. Now I wrote this and I can't get it working.
    Code:
    # include <io.h>
    
    void ShowLNGFiles() 
    {
       struct _finddata_t File01;
       long int Search, i=0;
    
       Search= _findfirst("*.*", &File01);
       while (!Search)
       {
           i++;
           printf("%s", File01.name);
           Search = _findnext(0, &File01);
       }
       if (i == 0)
       {
           printf("\nNot working.");
       }
    }
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  9. #9
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    ok other than not including stdio.h the only problem i see right of is you need to change your find string to something with a directory!

    Search= _findfirst("C:\\*.*", &File01);
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  10. #10
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Try this:

    void ShowLNGFiles()
    {
    DIR d = opendir("c:\\");

    struct _finddata_t File01;
    long int Search = 1, i=0;
    long int Handle;

    Handle = _findfirst("*.*", &File01);

    while (Search)
    {
    i++;
    printf("%s", File01.name);
    Search = _findnext(Handle, &File01);
    }
    if (i == 0)
    {
    printf("\nNot working.");
    }

    closedir( d );

    /*...might need to use findclose() too, look at your documentation, maybe in io.h, maybe dirent.h...*/
    }

    Let me know if that works...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  11. #11
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    By the way, Salem posted an excellent example some time back. Do a search on the boards to find it...


    ...Here it is. One thing though, it needed a slight revision...


    Code:
    
    //...Author: Salem A.K.A. "stee"
    
    #include <stdio.h>
    #include <dir.h>
    #include <string.h>
    
    #define ALL_ATTS ( \
      FA_DIREC | \
      FA_ARCH )
    
    void walker ( char *path ) {
      struct ffblk finder;
      unsigned int res;
    
    
     chdir(path);  //...added this so you don't crash...
    
      for ( res = findfirst ( "*.*", &finder, ALL_ATTS );
            res == 0;
            res = findnext( &finder ) ) {
        if ( strcmp(finder.ff_name, ".") == 0 ) continue;  // current dir
        if ( strcmp(finder.ff_name, "..") == 0 ) continue; // parent dir
    
        // if its a directory, examine it
        // else compare the filename with the one we're looking for
        if ( finder.ff_attrib & FA_DIREC ) {
          char newpath[MAXPATH];
          strcpy( newpath, path );
          strcat( newpath, "\\" );
          strcat( newpath, finder.ff_name);
          chdir( finder.ff_name );
          walker( newpath );
          chdir( ".." );
        } else {
          if ( strcmp( finder.ff_name, "words.txt" ) == 0 ) {
            printf( "Found!!!" );
          }
        }
      }
    }
    
    int main ( ) {
      char *root = "\\";
      chdir( root );
      walker( root );
      return 0;
    }

    To make it fit your needs, just add another parameter to the function...Tho now that I think about it, this looks a little incomplete...still, try it.
    Last edited by Sebastiani; 04-27-2002 at 01:58 PM.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  12. #12
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    This example is for DOS based program and not for the win32 console program. Anyway I fixed the code and it is working now.
    Here's the code:
    Code:
    void ShowLNGFiles ()
    {
        struct _finddata_t File;
        long int Search= 0, Handle = 0;
        int i = 0;
        BOOL Loop = TRUE;
    	
        Handle = _findfirst("C:\\*.lng", &File); // returns -1 if there is no file, otherwise returns 6488923
        if (Handle != -1)
        {
           while (Loop)
           {
               printf("%s", File.name);
               Search = _findnext(Handle, &File); // returns 0 if the file is found, otherwise returns -1
               i++;
               if (Search == -1) Loop = FALSE; // if there is no files more to be found then exit the while loop
           }
        }
        else
        {
           printf ("File(s) with extension \"*.lng\" can not be found.");
        }
    }
    But I have one more question. When I was programming in Turbo C++ 3.0 (for DOS) and if I want to define my current directory I had to write this ".\myprog\". My problem is that this is not working with VC++ 6.0. How to define my current directory?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  13. #13
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    This may work:

    char buff[500];

    getcwd(buff, 500);
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  14. #14
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    You miss understood.

    Code:
    Handle = _findfirst("C:\\*.lng", &File);
    // how to rewrite "C:\\*.lng" into something independent ??
    // something like this "./myprog/*.lng" -> this works only under Turbo C++ 3.0 compiler.
    EDIT:

    Ok, I fixed it. It is working now.

    Thanks guys for you answers.
    Last edited by GaPe; 04-28-2002 at 04:06 AM.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Create Copies of Files
    By Kanshu in forum C++ Programming
    Replies: 13
    Last Post: 05-09-2009, 07:53 AM
  2. Reading .dat files from a folder in current directory...
    By porsche911nfs in forum C++ Programming
    Replies: 7
    Last Post: 04-04-2009, 09:52 PM
  3. WM_COPYDATA and mutex selecting multiple files
    By gh0st in forum Windows Programming
    Replies: 2
    Last Post: 10-27-2006, 02:22 PM
  4. Folders and text files
    By tim545666 in forum C++ Programming
    Replies: 11
    Last Post: 02-17-2002, 04:15 PM
  5. reinserting htm files into chm help files
    By verb in forum Windows Programming
    Replies: 0
    Last Post: 02-15-2002, 09:35 AM