Solved

Including space in path for windows 2000

Posted on 2004-08-06
3
370 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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