cancel
Showing results for 
Search instead for 
Did you mean: 

move files -javascript

meethrishi
Champ in-the-making
Champ in-the-making
I am trying to move a document to a destination folder using javascript API.
The problem is if the document with same name already exists in the repository, the move does not work and throws error.
is there any way i can overwrite the document if it already exists through move api?
here is my code
var rootSpaceName = companyhome.childByNamePath("nodename");
var childList = rootSpaceName.children;
var count = childList.length;
var test = new Array();

for(var i=0; i
{
var childName = childList.properties.name;
var child = childList;

if(!child.isContainer)
{
var newSpace = childName.substring(0,4);
var ind = 0;

var existingSpace = rootSpaceName.childByNamePath(newSpace);
child.move(existingSpace) // this code fails if the document with same name already exists in the space
}
4 REPLIES 4

mitpatoliya
Star Collaborator
Star Collaborator
You can just check that if file exist delete the existing file.


add these piece of code

//check and remove existing file
var existing_file=existingSpace.childByNamePath(child.name);
                               if(existing_file!=null)
                               { existing_file.remove();}

before this line
child.move(existingSpace)

meethrishi
Champ in-the-making
Champ in-the-making
thanks but unfortunately i can not do it.
if i delete then all the existing metadata and aspects of that file will be removed when i delete the file.
and the files that i am working with are PDFs.

mrogers
Star Contributor
Star Contributor
You don't want to be using move then!

Sounds like you should be copying your node if target does not exist.  Else just updating the content in your target node.

meethrishi
Champ in-the-making
Champ in-the-making
correct but updating content if its text file is easy. if the files are PDF, how can i ?