Click here to Skip to main content
15,886,106 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.........
Posted

You have to #include <direct.h>.
 
Share this answer
 
v2
Comments
virus131 11-Apr-11 6:02am    
Thanks for your answer...... got error resolve...
but how do I know, the directory has been changed? Actually I am new to VC++ and a fresher, so i dont know much more about this. Could you please tell me how to change directory and display all subdirectories of the changed directory?
Please help me.. thanx alot in advance.....
Niklas L 11-Apr-11 6:33am    
Check out FindFirstFile() and FindNextFile() API on MSDN.
Sandeep Mewara 11-Apr-11 10:50am    
Good answer. My 5!
ShilpiP 11-Apr-11 23:42pm    
Thanks
I am creating mfc application to change directory

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.

[Edit]
-------

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.
 
Share this answer
 
v2
Comments
Wendelius 11-Apr-11 12:42pm    
Good point, my 5.
Stefan_Lang 13-Apr-11 4:22am    
Exactly what I thought!

Makes me wonder though what chdir in the Dos box does though...
Nish Nishant 13-Apr-11 9:03am    
It calls an INT 21h function to set the current directory. This was a global setting.
Albert Holguin 13-Apr-11 10:19am    
its also very easy to change the cwd by other functions in an app, so you shouldn't trust it to remain the same for the entire time you run an application.
Nish Nishant 13-Apr-11 10:22am    
Yeah, good point.
Hey you can used,

BOOL SetCurrentDirectory(
   LPCTSTR pstrDirName 
);

instead of chdir
For changing directory.
like
CString path="C:\\MyPrg\\"";
SetCurrentDirectory(path);


REGARD santosh.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900