Header File
dir.h
Category
Directory Control Routines
Prototype
int fnsplit(const char *path, char *drive, char *dir, char *name, char *ext);
int _wfnsplit(const wchar_t *path, wchar_t *drive, wchar_t *dir, wchar_t *name, wchar_t *ext );
Description
Splits a full path name into its components.
fnsplit takes a file's full path name (path) as a string in the form X:\DIR\SUBDIR\NAME.EXT and splits path into its four components. It then stores those components in the strings pointed to by drive, dir, name, and ext. All five components must be passed but any of them can be a null which means the corresponding component will be parsed but not stored. If any path component is null, that component corresponds to a non-NULL, empty string.
The maximum sizes for these strings are given by the constants MAXDRIVE, MAXDIR, MAXPATH, MAXFILE, and MAXEXT (defined in dir.h) and each size includes space for the null-terminator.
fnsplit assumes that there is enough space to store each non-null component.
Return Value
fnsplit returns an integer (composed of five flags defined in dir.h) indicating which of the full path name components were present in path. These flags and the components they represent are
EXTENSION |
An extension |
FILENAME |
A file name |
DIRECTORY |
A directory (and possibly subdirectories) |
DRIVE |
A drive specification (see dir.h) |
WILDCARDS |
Wildcards (* or ?) |
Example
#include <stdlib.h> #include <stdio.h> #include <dir.h> int main(void) { char *s; char drive[MAXDRIVE]; char dir[MAXDIR]; char file[MAXFILE]; char ext[MAXEXT]; int flags; s=getenv("COMSPEC"); /* get the comspec environment parameter */ flags=fnsplit(s,drive,dir,file,ext); printf("Command processor info:\n"); if(flags & DRIVE) printf("\tdrive: %s\n",drive); if(flags & DIRECTORY) printf("\tdirectory: %s\n",dir); if(flags & FILENAME) printf("\tfile: %s\n",file); if(flags & EXTENSION) printf("\textension: %s\n",ext); return 0; }
Portability
|
POSIX |
Win32 |
ANSI C |
ANSI C++ |
fnsplit |
|
+ |
|
|
_wfnsplit |
|
NT only |
|
|
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|