Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CopyFIle help required

Status
Not open for further replies.

petya1

Technical User
Sep 11, 2003
4
CA
I can not understand the behavior of the CopyFile function.

I wrote small program. In the program I want to create a new project.
I click on the New and custom NewDlg appears. In the location I type
E:\Projects\NewProject1 \( note that there is the space after NewProject1)
I get this string and create dir with the space at the end by using _wmkdir function. Then I want to copy some files from some location to E:\Projects\NewProject1 \(note that there is the space at the end). CopyFiles fails to do that. I checked the destination string it is still has the space and it looks like this E:\Projects\NewProject1 \file.txt.
I was curios and started cmd.exe. I tried to change dir to the newly created folder
E:\Projects> cd NewProject1 (with space at the end and without) and I’ve got the error stating “can not find specified location”

Then I change the function _wmkdir to CreateDirectoryw in my program and did exactly the same as explained above. CopyFiles failed again but in the dos prompt I was able to change directory to the newly created dir when I was typing space at the end.

Then I used mkdir to create directory. CopyFiles failed again but in the dos prompt I was able to change directory to the newly created when I typed the name of the dir with and without space at the end.

If I type E:\Projects\New Project1\ (with space anywhere but at the end) Everything works fine.

I am using winXp and VS 6.0.

I will appreciate any explanation.

Thanks.
 
I am not sure if spaces are allowed at the end of directory names... (or why you might want to?)

Also, have you checked the return value of _wmkdir. if it is -1, then you can look at errno to see what the problem is.

MSDN Quote
"
Return Value
Each of these functions returns the value 0 if the new directory was created. On an error the function returns –1 and sets errno as follows:

EEXIST
Directory was not created because dirname is the name of an existing file, directory, or device.
ENOENT
Path was not found.
"
hth,

K
 
I checked the return value. It is 0.
I also veified that directory was created. I can see it in windows explorer. I assume that the space at the end is the problem.
 
OK, I misunderstood you, sorry.
I take it there are no permissions set up on the folder (hidden, locked etc ?)

The space must be the proble, I have tried to create a folder like yours and I can't.

If you don't want the spaces, then all I can suggest is that you ensure that you remove them frm your string before you pass them to makedir

I'd guess that this is a limitation of the system, and you cannot do what you want though, sorry. (can you create something in the folder via explorer ?

K
 
I agree with Kalisto that you should not create folders with spaces starting or ending the names. However the following code did work for me in VC6 on Windows 2000 Pro.
Code:
TCHAR* dir = _T("c:\\research\\foo \\");
cout << &quot;makedir: &quot; << _tmkdir( dir) << endl;
cout << &quot;copy: &quot; << 
	CopyFile(_T(&quot;c:\\research\\xmlrnd.js&quot;), 
	_T(&quot;c:\\research\\foo \\xmlrnd.js&quot;), TRUE) <<
	endl;

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top