www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/31/23:04:04

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: File Paths and Directories
Date: Wed, 30 Jul 1997 20:42:24 +0000
Organization: Two pounds of chaos and a pinch of salt
Lines: 43
Message-ID: <33DFA730.2908@cs.com>
References: <5rllpr$5vc$1 AT excalibur DOT flash DOT net>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp106.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Joshua Eckstein wrote:
> 
> I'm trying to find out how to specify a filename as not to be
> drive/directory specific. In other words, if someone puts the executable in
> [xfolder] and I have established a branch directory for data, it will look
> in [xfolder]\data. Like so:
> 
> LoadPic ("\data\example.pic", ...);

Omit the beginning slash.  This makes the path relative to the current
working directory.  If you're looking for a data file that will always
be in a subdirectory of your program's installation directory, then you
can find the correct drive/directory by examining argv[0], which should
contain the full pathname of the executable.

Example:

#include <stdio.h>
#include <dir.h>

int main( int argc, char *argv[] )
{
    char progdir[FILENAME_MAX], filename[FILENAME_MAX];
    char drive[MAXDRIVE], dir[MAXDIR], name[MAXFILE], ext[MAXEXT];

    fnsplit( argv[0], drive, dir, name, ext );
    sprintf( progdir, "%s%s", drive, dir );

    /* ... */

    sprintf( filename, "%s%s", progdir, "example.pic" );
    LoadPic( filename, /* ... */ );

    /* ... */
    return 0;
}

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I |     mailto:fighteer AT cs DOT com      |
| Proud owner of what might one   |   http://www.cs.com/fighteer    |
| day be a spectacular MUD...     | Plan: To make Bill Gates suffer |
---------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019