Solved

Including space in path for windows 2000

Posted on 2004-08-06
3
367 Views
Last Modified: 2010-04-24
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
0
Comment
Question by:sriamar
3 Comments
 
LVL 7

Accepted Solution

by:
jimwasson earned 250 total points
ID: 11737818
First of all, in C or C++ you have to use an escale sequence for the '\' in the string (like '\\'):

    destfile = "C:\pic.bmp";

should be

destfile = "C:\\pic.bmp";

If you need to expand the short names to long names on Win2K+ you can use GetLongPathName():

DWORD GetLongPathName( LPCTSTR lpszShortPath, LPTSTR lpszLongPath, DWORD cchBuffer)
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11738093
You must use quotes:

sprintf(syscommand,"copy \"%s\" \"%s\"",szFilename,destfile);
0
 

Author Comment

by:sriamar
ID: 11738192
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
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question