?
Solved

Including space in path for windows 2000

Posted on 2004-08-06
3
Medium Priority
?
375 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Accepted Solution

by:
jimwasson earned 750 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

764 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