Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

accessing directories c++ DOS

  • 07-12-2002 11:37PM
    #1
    Posts: 431 ✭✭


    Hey all,

    Does anyone have an idea on how to access directories through c++?

    I'm sure there's a simple way to do it, it's wrecking my head at the mo, i'd like to display the listing of the directory, find the executable files and display a menu, giving the option to execute them.

    I'm sure it would be better through batch files but I'd like to see i could use directories through c++.

    Any help would be great
    thanks


Comments

  • Closed Accounts Posts: 5,563 ✭✭✭Typedef


    In DOS not a clue.

    If you are allowed to use *nix (or indeed if the pertinent libraries have been ported to mingw) you might want to check out dirent.

    man dirent.


  • Posts: 431 ✭✭ [Deleted User]


    thanks :)


  • Closed Accounts Posts: 1,006 ✭✭✭theciscokid


    i probably way off here but is that not

    C:\Documents and Settings\theciscokid>

    C:\Documents and Settings\theciscokid>cd desktop

    C:\Documents and Settings\theciscokid\desktop>

    then just do dir for a list


  • Registered Users, Registered Users 2 Posts: 95 ✭✭Mr.StRiPe


    The code within this function should do the trick. It displays all files with .DEMO extensions in the specified dir. You should be able to modify it to what ever you want. You'll also need to #include <io.h>

    void dir()
    {
    index = 0;
    struct _finddata_t demo_file;
    long hFile;


    /* Find first .demo file in current directory */
    if( (hFile = _findfirst( "data/demos/*.demo", &demo_file )) == -1L )
    {
    //print( "No *.demo files in current directory!" );
    strcpy(demofile[index++], "No *.demo files in current directory!");
    }


    else
    {

    //print( "Listing of .demo files" );endl();endl();

    strcpy(demofile[index++], demo_file.name);
    //print(demo_file.name);endl();

    /* Find the rest of the .demo files */
    while( _findnext( hFile, &demo_file ) == 0 )
    {
    strcpy(demofile[index++], demo_file.name);
    //print(demo_file.name); endl();
    }

    _findclose( hFile );
    }
    }


  • Posts: 431 ✭✭ [Deleted User]


    Thanks for the code snippet
    :)


  • Advertisement
Advertisement