Header File
dir.h
Category
Directory Control Routines
Prototype
int getcurdir(int drive, char *directory);
int _wgetcurdir(int drive, wchar_t *directory );
Description
Gets current directory for specified drive.
getcurdir gets the name of the current working directory for the drive indicated by drive. drive specifies a drive number (0 for default, 1 for A, and so on). directory points to an area of memory of length MAXDIR where the null-terminated directory name will be placed. The name does not contain the drive specification and does not begin with a backslash.
Return Value
getcurdir returns 0 on success or -1 in the event of error.
Example
#include <dir.h> #include <stdio.h> #include <string.h> char *current_directory(char *path) { strcpy(path, "X:\\"); /* fill string with form of response: X:\ */ path[0] = 'A' + getdisk(); /* replace X with current drive letter */ getcurdir(0, path+3); /* fill rest of string with current directory */ return(path); } int main(void) { char curdir[MAXPATH]; current_directory(curdir); printf("The current directory is %s\n", curdir); return 0; }
Portability
|
POSIX |
Win32 |
ANSI C |
ANSI C++ |
getcurdir |
|
+ |
|
|
_wgetcurdir |
|
NT only |
|
|
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|