Getting and Setting current Directory
void main() {
char olddir[MAX_PATH];
if (GetCurrentDirectory(MAX_PATH, olddir) == 0) {
errormessage();
//exit(1);
}
MessageBox(NULL,olddir,L"File",MB_OK);
_tprintf(TEXT("Current Directory %s\n"),olddir);
if(SetCurrentDirectory("C:\\Documents and settings") == 0)
errormessage();
if (GetCurrentDirectory(MAX_PATH, olddir) == 0) {
errormessage();
}
_tprintf(TEXT("Current Directory %s\n"),olddir);
getch();
}
I have been using this code to get and set my current directory but when setting the directory it always displays the error "The System can't find the file specified"
while getting the file it displays this as the current directory
Current Directory c:\Documents and Settings\Administrator\My Documents\Visual St
udio 2005\Projects\Scorta\TEST
Re: Getting and Setting current Directory
I does not look wrong actually. I assume your "errormessage()" prints
the GetLastError() result.
You should try to add a backslash "\\" as last character even if SetCurrentDirectory should do
that for you.
If that does not work, check if you have enough permissions on the directory.
Re: Getting and Setting current Directory
thankx a lot its done
actually i changed the line
if(SetCurrentDirectory("C:\\Documents and settings") == 0)
to
if(SetCurrentDirectory(L"C:\\Documents and settings") == 0)
converting intowide character.
I don't have any idea why it worked can you explain it
thnx in advance
Re: Getting and Setting current Directory
Your original code never would have compiled because of the mix of character types. Therefore, you never would have got an error message. So why did you post the question?
Re: Getting and Setting current Directory
Quote:
Originally Posted by
0xC0000005
Your original code never would have compiled because of the mix of character types. Therefore, you never would have got an error message. So why did you post the question?
The code compiled on visual studio 2005 but I don't know Why ?