Erdem Güngör
Erdem Güngör

Reputation: 877

Eclipse Plugin: Copy File

i want to copy a file from a folder1 to folder2 in my eclipse project.

Here is my code:

IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot root = workspace.getRoot();
    IProject project = root.getProject(getSelectedProject().toString());

    IFolder folder = project.getFolder("www/GeneratedFiles");

    IFolder folder2 = project.getFolder("AppGenerator/TableFiles");

    IFile file = folder2.getFile("RelationsBC.bbTable");

    System.out.println("FileName: " + file.getName().toString());

    if (!project.exists())
        project.create(null);
    if (!project.isOpen())
        project.open(null);
    if (!folder.exists()) {
        folder.create(true, true, null);
        file.copy(folder.getFullPath(), true, null);
    } else {
        file.copy(folder.getFullPath(), true, null);
    }

When I run my Plugin, folder.create(true, true, null) works fine but file.copy(folder.getFullPath(), true, null); gives me an error.

org.eclipse.core.internal.resources.ResourceException: Resource '/todo/www/GeneratedFiles' already exists.

What I am doing wrong? Hope u can understand me fine.

Upvotes: 0

Views: 841

Answers (1)

greg-449
greg-449

Reputation: 111142

The destination path parameter of copy should be the name of a file, you are using the name of the folder.

Use something like:

IPath path = folder.getFullPath();

path = path.append(file.getName());

file.copy(path, true, null);

Upvotes: 2

Related Questions