2013-01-24 3 views
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 줄 뒤에 FileError.PATH_EXISTS_ERR이라는 오류 12가 발생했습니다. 하지만 폴더 나 파일이 sdcard에 없습니다.

https://github.com/torrmal/cordova-simplefilemanagement

당신은 재귀 적으로 만들 수 있습니다 디렉토리 :

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); 
+0

는 @ dhaval이 [링크] (http://stackoverflow.com/questions/10961000/nested-directory-creator-phonegap) 여기 내 코드'window.requestFileSystem (LocalFileSystem.PERSISTENT, 0, function (fileSystem) { window.FS = fileSystem; var printDirPath = function (entry) { console.log ("Dir path -"+ entry.fullPath);} createDirectory (folder, localFileName, remoteFile, printDirPath); }, 실패);'@dhaval의 디렉토리 생성 메소드를 사용했습니다. – engincancan

답변

1

코르도바 - phoengap에 대한 간단한 파일 관리자가 내가 솔루션의 대답에 내 자신을 찾을 수

//CREATE A DIRECTORY RECURSIVELY 

new DirManager().create_r('folder_a/folder_b',Log('created successfully')); 
관련 문제