3

How to rename a directory using JavaScript file system API?

I tried as given below:

dirNameWithPath = '/MyPictures3/New Folder';
newDirName = 'newTitle';
dirPath = '/MyPictures3';

filesystem.root.getDirectory(dirNameWithPath, {}, function(dirEntry) {
    dirEntry.moveTo(dirPath, newDirName, callback, errorHandler);
}); 

I am getting the following error:

FileError.INVALID_MODIFICATION_ERR
4
  • Is that even possible? You might accidentally overwrite some other directory (or fail, gaining knowledge) Commented Jan 1, 2013 at 7:35
  • which browser are you using? Commented Jan 1, 2013 at 7:43
  • @JanDvorak What not possible? renaming a directory? renaming directory is possible. see html5rocks.com/en/tutorials/file/filesystem. It is not overwriting. Commented Jan 1, 2013 at 8:26
  • @Guy Google Chrome Version 23.0.1271.52 beta. Commented Jan 1, 2013 at 8:26

1 Answer 1

2

The first parameter of moveTo must be a DirectoryEntry (not a String):

void moveTo(DirectoryEntry parent,
            optional DOMString newName,
            optional EntryCallback successCallback,
            optional ErrorCallback errorCallback);

The parent parameter is "The directory to which to move the entry".

And "entry" is the directory to be moved/renamed (directory.moveTo(newLocation, newName)).

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, that was the mistake!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.