更改目录时出错 [英] Error in changing directory

查看:104
本文介绍了更改目录时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在创建mfc应用程序以更改目录,为此,我尝试使用chdir(),但它给出了类似"chdir-未声明的标识符"的错误.是否需要包含头文件?如果是这样,那我应该包括哪个头文件?

谢谢......

Hi,
I am creating mfc application to change directory, for this I tried chdir(), but it gives error like- "chdir- an undeclared identifier". Is there a need to include header file? If so then which header file should i include?

Thanx.........

推荐答案

You have to #include <direct.h>.


我正在创建MFC应用程序更改目录


当您收到响应告诉您如何执行此操作(例如-通过使用SetCurrentDirectory)时,请注意,这可能无法实现您似乎在此处尝试执行的操作.它只会为您的进程设置当前目录.进程退出后,您启动的任何其他进程都不会在该目录中启动.与DOS时代不同,您无法设置全局当前目录.


-------

将此内容发表为评论,但认为琐事在答案中也会很有趣.

在DOS时代,chdir所做的是调用INT 21h(函数3Bh)来设置当前目录.这是一个全球性的环境.此外,还分别记住并维护了每个驱动器的当前目录.

当然,如果您使用的是自定义外壳程序(而不是command.com),则此行为可能会有所不同.


While you have got responses telling you how to do this (example - by using SetCurrentDirectory), be aware that this may not achieve what you seem to be trying to do here. It will only set the current directory for your process. Once your process exits, any other process you start will not start in this directory. Unlike in the DOS days, you cannot set a global current directory.


-------

Posted this as a comment but thought the trivia would be interesting in the answer too.

In the DOS days what chdir did was to call INT 21h (function 3Bh) to set the current directory. This was a global setting. In addition the current directory for each drive was also separately remembered and maintained.

Of course if you used a custom shell (and not command.com) then this behavior could vary.


嘿,您可以使用,

Hey you can used,

BOOL SetCurrentDirectory(
   LPCTSTR pstrDirName 
);


代替chdir
用于更改目录.
喜欢


instead of chdir
For changing directory.
like

CString path="C:\\MyPrg\\"";
SetCurrentDirectory(path);



regant santosh.



REGARD santosh.


这篇关于更改目录时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆