Link to home
Start Free TrialLog in
Avatar of sriamar
sriamar

asked on

Including space in path for windows 2000

Hi,
I have  to copy a file form one location to another using c++ in windows 2000. I have the following code.

//I use the CFileDialog Dlg to get the file location
szFilename = Dlg.GetPathName();
destfile = "C:\pic.bmp";

char syscommand[350];
sprintf(syscommand,"copy %s %s",szFilename,destfile);
AfxMessageBox(syscommand);
int i = system(syscommand);
if(i != 0)
{
      AfxMessageBox( "Could not copy because file is in desktop or file name has space in between");
}

when the source file is in desktop......then the path wil be
c:\Documents ans Settings\Administrator\Desktop\pic.bmp but as windows 2000 represents it as
C:\DOCUME~1\ADMINI~1\DESKTOP my code above doesnt work.

How do I solve this problem. Thankyou

Amar
ASKER CERTIFIED SOLUTION
Avatar of jimwasson
jimwasson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You must use quotes:

sprintf(syscommand,"copy \"%s\" \"%s\"",szFilename,destfile);
Avatar of sriamar
sriamar

ASKER

Hi
Yea The problem was converting long file name to the short file name. Once I saw GetLongPathName i found the "GetShortPathName(...)" and it did the trick.Thanks a lot Jimwasson

and  jaime_olivares thanks for ur answer. sprintf i have mentioned above works and I see no problem with it.

Thankyou guys
amar