9
我的目標是創建一個文件夾,如「/ sdcard/files/excel /」或「/ sdcard/files/pdf /」。 sdcard
之後的部分來自url(「/ files/excel」)。所以首先我要檢查「/ files/excel」是否存在,然後創建一個文件,如果它不存在。該名稱來自名爲「localFileName」的url。Phonegap:在特定文件夾中創建文件
在這種情況下,folder =「files/excel」和localFileName =「Sheet1.html」。
在fs.root.getDirectory行之後,我得到了Error 12,名爲FileError.PATH_EXISTS_ERR ,但sdcard中沒有文件夾或文件。
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
var folder = file_path.substring(0,file_path.lastIndexOf('/'));
console.log(folder);
fs.root.getDirectory(folder,{create: true, exclusive: false},function (datadir) {
console.log(folder);
datadir.getFile(localFileName, {create: true, exclusive: false},function(fileEntry) {
var ft = new FileTransfer();
yol = "/sdcard/"+folder+localFileName;
ft.download(remoteFile,yol,function(entry) {
console.log(entry.fullPath);
}, fail);
}, fail);
}, fail);
}, fail);
我找到解決辦法我自己在的答案@ dhaval在這[鏈接](http://stackoverflow.com/questions/10961000/nested-directory-creator-phonegap)所以這裏是我的代碼'window.requestFileSystem(LocalFileSystem.PERSISTENT,0, 函數(fileSystem) window.FS = fileSystem; (文件夾,localFileName,remoteFile,printDirPath);我們可以通過下面的代碼來創建一個文件夾: },失敗);'我使用@dhaval的創建目錄方法 – engincancan