Solved

Including space in path for windows 2000

Posted on 2004-08-06
3
361 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
Comment Utility
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
Comment Utility
You must use quotes:

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

Author Comment

by:sriamar
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now