Skip to content

Latest commit

 

History

History
128 lines (100 loc) · 4.46 KB

chdir-wchdir.md

File metadata and controls

128 lines (100 loc) · 4.46 KB
descriptiontitlems.dateapi_nameapi_locationapi_typetopic_typef1_keywordshelpviewer_keywords
Learn more about: _chdir, _wchdir
_chdir, _wchdir
4/2/2020
_wchdir
_chdir
_o__chdir
_o__wchdir
msvcrt.dll
msvcr80.dll
msvcr90.dll
msvcr100.dll
msvcr100_clr0400.dll
msvcr110.dll
msvcr110_clr0400.dll
msvcr120.dll
msvcr120_clr0400.dll
ucrtbase.dll
api-ms-win-crt-filesystem-l1-1-0.dll
DLLExport
apiref
tchdir
_chdir
_wchdir
_tchdir
wchdir
_tchdir function
_chdir function
_wchdir function
tchdir function
wchdir function
chdir function
directories [C++], changing

_chdir, _wchdir

Changes the current working directory.

Syntax

int_chdir( constchar*dirname ); int_wchdir( constwchar_t*dirname );

Parameters

dirname
Path of new working directory.

Return value

These functions return a value of 0 if successful. A return value of -1 indicates failure. If the specified path couldn't be found, errno is set to ENOENT. If dirname is NULL, the invalid parameter handler is invoked, as described in Parameter validation. If execution is allowed to continue, errno is set to EINVAL and the function returns -1.

Remarks

The _chdir function changes the current working directory to the directory specified by dirname. The dirname parameter must refer to an existing directory. This function can change the current working directory on any drive. If a new drive letter is specified in dirname, the default drive letter is changed as well. For example, assume A is the default drive letter and \BIN is the current working directory. The following call changes the current working directory for drive C to \temp and establishes C as the new default drive:

_chdir("c:\\temp");

When you use the optional backslash character (\) in paths, you must place two backslashes (\\) in a C string literal to represent a single backslash (\).

_wchdir is a wide-character version of _chdir; the dirname argument to _wchdir is a wide-character string. _wchdir and _chdir behave identically otherwise.

By default, this function's global state is scoped to the application. To change this behavior, see Global state in the CRT.

Generic-text routine mapping

Tchar.h routine_UNICODE and _MBCS not defined_MBCS defined_UNICODE defined
_tchdir_chdir_chdir_wchdir

Requirements

RoutineRequired headerOptional header
_chdir<direct.h><errno.h>
_wchdir<direct.h> or <wchar.h><errno.h>

For more compatibility information, see Compatibility.

Example

// crt_chdir.c// arguments: C:\WINDOWS/* This program uses the _chdir function to verify that a given directory exists. */#include<direct.h>#include<stdio.h>#include<stdlib.h>#include<errno.h>intmain( intargc, char*argv[] ) { if(_chdir( argv[1] ) ) { switch (errno) { caseENOENT: printf( "Unable to locate the directory: %s\n", argv[1] ); break; caseEINVAL: printf( "Invalid buffer.\n"); break; default: printf( "Unknown error.\n"); } } elsesystem( "dir *.exe"); }
Volume in drive C has no label. Volume Serial Number is 2018-08A1 Directory of c:\windows 08/29/2002 04:00 AM 1,004,032 explorer.exe 12/17/2002 04:43 PM 10,752 hh.exe 03/03/2003 09:24 AM 33,792 ieuninst.exe 10/29/1998 04:45 PM 306,688 IsUninst.exe 08/29/2002 04:00 AM 66,048 NOTEPAD.EXE 03/03/2003 09:24 AM 33,792 Q330994.exe 08/29/2002 04:00 AM 134,144 regedit.exe 02/28/2003 06:26 PM 46,352 setdebug.exe 08/29/2002 04:00 AM 15,360 TASKMAN.EXE 08/29/2002 04:00 AM 49,680 twunk_16.exe 08/29/2002 04:00 AM 25,600 twunk_32.exe 08/29/2002 04:00 AM 256,192 winhelp.exe 08/29/2002 04:00 AM 266,752 winhlp32.exe 13 File(s) 2,249,184 bytes 0 Dir(s) 67,326,029,824 bytes free 

See also

Directory control
_mkdir, _wmkdir
_rmdir, _wrmdir
system, _wsystem

close