在PhoneGap应用程序中创建目录

Joh*_*mez 19 filesystems directory mobile cordova

试图找出如何使用PhoneGap在文件系统上创建目录.

我想为我的PhoneGap应用程序创建一个目录,这样我就可以存储用户在那里创建的图像并将其加载到应用程序中.

Tit*_*eul 40

这是你如何做到的:

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onRequestFileSystemSuccess, null); 

function onRequestFileSystemSuccess(fileSystem) { 
        var entry=fileSystem.root; 
        entry.getDirectory("example", {create: true, exclusive: false}, onGetDirectorySuccess, onGetDirectoryFail); 
} 

function onGetDirectorySuccess(dir) { 
      console.log("Created dir "+dir.name); 
} 

function onGetDirectoryFail(error) { 
     console.log("Error creating directory "+error.code); 
} 
Run Code Online (Sandbox Code Playgroud)

在iOS上,此脚本将在Applications/YOUR_APP/Documents /中创建名为"example"的目录

  • 是的,这很有效.因为我发现了这个问题,我正准备回答我的问题.有趣的是我怎么找不到答案,直到我发布它,然后我立即找到它. (3认同)