gpt4 book ai didi

ios - 获取 tmp 文件夹的路径并删除 iOS phonegap/cordova 上的内容

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:16:53 25 4
gpt4 key购买 nike

我很难理解 phonegap/codrova file api 文档。

如何找到应用程序的 tmp 文件夹的路径,然后在不删除文件夹本身的情况下列出/删除内容?

这具体涉及删除当我从设备的图片库中提取照片时创建的临时图像文件。

最佳答案

此函数使用cordova文件插件从tmp文件夹中删除特定文件

deleteFile: function(fileName) {

var that = this;

if (!fileName) {
console.error("No fileName specified. File could not be deleted.");
return false;
}

window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function(fileSystem){ // this returns the tmp folder

// File found
fileSystem.root.getFile(fileName, {create: false}, function(fileEntry){
fileEntry.remove(function(success){
console.log(success);
}, function(error){
console.error("deletion failed: " + error);
});
}, that.get('fail'));
}, this.get('fail'));

}

您可以稍微调整一下,先找到所有文件并删除它们。像这样

window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function(fileSystem){ {
var reader = fileSystem.root.createReader();
reader.readEntries(function(entries) {

var i;
for (i = 0; i < entries.length; i++) {
if (entries[i].name.indexOf(".png") != -1) {
// delete stuff from above could go in here
}
}
}, fail);
}

关于ios - 获取 tmp 文件夹的路径并删除 iOS phonegap/cordova 上的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21409215/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com