|
-
December 18th, 2008, 07:21 AM
#1
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
-
December 19th, 2008, 05:31 AM
#2
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.
-
December 19th, 2008, 05:48 AM
#3
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
-
December 19th, 2008, 07:47 AM
#4
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?
-
December 27th, 2008, 01:45 AM
#5
Re: Getting and Setting current Directory
 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 ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|