Is there any way to change directory using C language?

∥☆過路亽.° 提交于 2019-11-26 21:02:47

Depending on your OS there are different calls for changing the current directory. These will normally only change the current dir of the process running the executable. After the process exits you will be in the directory you started in.

Michael Foukarakis

The chdir() function. For more info, use man chdir.

Santak Dalai

chdir() changes only the current working directory of the process but not of the context in which you are working. Suppose you execute a program in the terminal and your current directory is /home/Documents, then on executing a program having the following lines

chdir("cd ../Downloads");

will not change the working directory of the terminal, but changes that of the process only.

Dmitry Brant

Well, the POSIX command for changing the current directory is:

chdir(const char*path);

See the recent POSIX documentation for chdir() is here.

Yes, the chdir() function.

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char* argv[])
{
    system("C:\\windows\\notepad.exe");
    chdir("C:\\windows\\desktop");
    return 0;
}

As per this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!