From: "John M. Aldrich" 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 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk 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 #include 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 | ---------------------------------------------------------------------