HTML5 File API modify file.name

陌路散爱 提交于 2019-12-05 18:15:32

I assume that you are using HTML5 File API to store sandboxed file to local file system. You have to get fileEntry object first if you want to modify an exist file's name:

window.webkitRequestFileSystem(window.TEMPORARY, 1024*1024, function(fs){
    fs.root.getFile("targetFileFullName",{},function(fileEntry){
        fileEntry.moveTo("original path","newName");
    },errorHandler);
}, onError);

FileEntry.moveTo function help you move or rename file. You just want rename it so all you have to do is assign new name to parameter two and do not change file path parameter.

I wrote a jsfiddl demo that show a list of your local storage files and a target name field means which file you want to modify and a new name input field:

After you press the change button. The "test3.txt" file will be modify:

Hope this is helpful for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!