RAD Studio
ContentsIndex
PreviousUpNext
searchpath, wsearchpath

Header File 

dir.h  

Category 

Miscellaneous Routines 

Prototype 

char *searchpath(const char *file); 

wchar_t *wsearchpath( const wchar_t *file ); 

Description 

Searches the operating system path for a file. 

searchpath attempts to locate file, searching along the operating system path, which is the PATH=... string in the environment. A pointer to the complete path-name string is returned as the function value. 

searchpath searches for the file in the current directory of the current drive first. If the file is not found there, the PATH environment variable is fetched, and each directory in the path is searched in turn until the file is found, or the path is exhausted. 

When the file is located, a string is returned containing the full path name. This string can be used in a call to access the file (for example, with fopen or exec...). 

The string returned is located in a static buffer and is overwritten on each subsequent call to searchpath. 

Return Value 

searchpath returns a pointer to a file name string if the file is successfully located; otherwise, searchpath returns null. 

Example  

#include <stdio.h>
#include <dir.h>
int main(void)
{
    char *p;
    /* Looks for ILINK32 and returns a pointer
       to the path  */
    p = searchpath("ILINK32.EXE");
    printf("Search for ILINK32.EXE : %s\n", p);
    /* Looks for nonexistent file  */
    p = searchpath("NOTEXIST.FIL");
    printf("Search for NOTEXIST.FIL : %s\n", p);
    return 0;
}

Portability

 
POSIX 
Win32 
ANSI C 
ANSI C++ 
searchpath 
 
 
 
wsearchpath 
 
NT only 
 
 
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!