有没有办法用C语言改变目录?

发布于 2024-08-02 08:35:14 字数 84 浏览 4 评论 0原文

有什么方法可以通过执行C 程序更改到任何目录吗?

Is there any way by which I can change to any directory by executing a C program?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

烟花易冷人易散 2024-08-09 08:35:14

chdir() 函数。有关更多信息,请使用 man chdir

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

攀登最高峰 2024-08-09 08:35:14

根据您的操作系统的不同,更改当前目录的调用也不同。这些通常只会更改运行可执行文件的进程的当前目录。进程退出后,您将位于您开始时所在的目录中。

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.

烛影斜 2024-08-09 08:35:14

chdir() 仅更改进程的当前工作目录,而不更改您正在工作的上下文。假设您在终端中执行一个程序,并且当前目录是 /home/Documents,那么执行具有以下几行的程序时

chdir("cd ../Downloads");

不会更改终端的工作目录,但会更改进程的工作目录仅有的。

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.

笑梦风尘 2024-08-09 08:35:14

那么,用于更改当前目录的 POSIX 命令是:

chdir(const char*path);

请参阅 最新 POSIX 文档 < code>chdir() 在这里

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

chdir(const char*path);

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

上课铃就是安魂曲 2024-08-09 08:35:14

是的,chdir() 函数。

Yes, the chdir() function.

优雅的叶子 2024-08-09 08:35:14
#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;
}

根据

#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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文