Overview
Features
Download
Documentation
Community
Add-Ons & Services

copyTo, moveTo : problem

Please post support and help requests here.

copyTo, moveTo : problem

Postby cdelmas » 20 Apr 2007, 15:03

I think there is a bug (or in fact, a misunderstanding) in copyTo/moveTo :
indeed, CopyFile cannot take a directory as destination path, only a file name. Thus, we have an exception thrown :
Code: Select all

Path p("C:\tmp\testPoco\test1");
File testDir(p);
testDir.createDirectories();
try {
   File f(p.parent().append(nextTotoName(0)));
   f.createFile();
   string dest(testDir.path());
   f.moveTo(dest);
} catch (FileAccessDeniedException& e) {
   cerr << e.displayText() << endl;
}

will display the error message. I think this should be patched very quickly, as documentation claims that target can be a directory.

Then, what about copying/moving a complete directory to another ?
cdelmas
 
Posts: 46
Joined: 22 Sep 2006, 10:04
Location: France

Re: copyTo, moveTo : problem

Postby guenter » 23 Apr 2007, 09:42

The bug is only in moveTo(); copyTo() correctly handles the target directory case.
Here's the fix for moveTo():
Code: Select all

void File::moveTo(const std::string& path)
{
   copyTo(path);
   removeImpl();
   setPathImpl(path);
}
guenter
 
Posts: 1105
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Re: copyTo, moveTo : problem

Postby cdelmas » 23 Apr 2007, 11:15

Thanks for your answer !
cdelmas
 
Posts: 46
Joined: 22 Sep 2006, 10:04
Location: France

Re: Re: Re: copyTo, moveTo : problem

Postby cdelmas » 24 Apr 2007, 10:24

There is still a problem : isDirectory returns false with my code, as _name isn't empty (_name == test1).
After a little search, the code located in parseWindows :
Code: Select all

if (it != end)
   pushDirectory(name);
else
   _name = name;

assigns _name with the last directory name. If I add a separator character at the end
Code: Select all

Path p("C:\tmp\testPoco\test1\");

That works well. So I have a question :
let 'p' a path for a directory (for instance, C: est). How can I verify that this path is really a path representing a directory, and not a file ? isDirectory won't work, because it will parse the name as if it was a file named C: est (a file without extension).

Any suggestion ?

(edit) : right, I was confusing Path: :isDirectory with File: :isDirectory. My apologies. That works fine !
cdelmas
 
Posts: 46
Joined: 22 Sep 2006, 10:04
Location: France


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests

cron