A library for accessing local file system for the current website on the browser
var myFile = new SFFileSystem({ options });
Property | Details |
---|---|
home | Set the root folder |
temporary | Store file to temporary storage that will vanish when the browser was refreshed |
callback | Callback if the initialization was success |
initError | Callback if the initialization was failed |
This is the current root folder
if(myFile.home.isDirectory === true)
console.log("I'm a folder");
// For other usage please check the 'Directory Entry' and 'Both Entry'
Get directory entry from directory path
myFile.path('/myFolder/subFolder', function(dirEntry){
dirEntry.isDirectory === true
}, console.error);
Check if file/folder was exist and return the type of the target
myFile.exist('/myFolder/subFolder', function(exist){
if(exist === 'file' || exist === 'folder')
console.log(true);
else
console.log(false);
}, console.error);
Get contents from a path and return an array of string
myFile.list('/myFolder', function(list){
list instanceof Array;
// ['myFile.txt', 'myFolder']
});
Get contents from a path and return their Entry
myFile.contents('/myFolder', function(list){
list instanceof Array;
// [FileEntry, DirectoryEntry, ...]
});
Create new folder and get it's Entry
dirEntry.newFolder('myFolder', function(subFolder){
subFolder.isDirectory === true;
});
Create new file and get it's Entry
dirEntry.newFile('myFile', function(fileEntry){
// fileEntry.write('stuff');
});
Go to deeper folder and return the Directory Entry
dirEntry.getFolder('myFolder', function(subFolder){
subFolder.isDirectory === true;
});
Get the file entry inside current folder
dirEntry.getFile('myFile', function(fileEntry){
fileEntry.isFile === true;
});
Check if file/folder was exist and return the type of the target
dirEntry.exist('myFolder', function(list){
if(exist === 'file' || exist === 'folder')
console.log(true);
else
console.log(false);
});
Get contents from current folder and return their Entry
dirEntry.contents(function(list){
list instanceof Array;
// [FileEntry, DirectoryEntry, ...]
});
Get contents from current folder and return their Entry
dirEntry.list(function(list){
list instanceof Array;
// ['myFile.txt', 'myFolder']
});
Write blob or string to current file
fileEntry.write('string' || new Blob(['any'], {type:"text/plain"}));
Append blob or string to current file
fileEntry.append('string' || new Blob(['any'], {type:"text/plain"}));
Read current file as a string
fileEntry.read(function(value){
console.warn(value);
});
// The alternative method is accessing the file from it's url
var url = fileEntry.toURL();
Rename current file/folder
anyEntry.remove();
dirEntry.removeRecursively();
Rename current file/folder
anyEntry.rename('targetName');
Copy current file/folder to other directory
anyEntry.copyTo('path' || DirectoryEntry);
Move current file/folder to other directory
anyEntry.moveTo('path' || DirectoryEntry);
Get parent directory for current file/folder
anyEntry.getParent(function(dirEntry){
dirEntry.isDirectory == true;
});
Return true is current entry is a file
if(anyEntry.isFile)
console.log("I'm a file");
Return true is current entry is a folder
if(anyEntry.isDirectory)
console.log("I'm a folder");
Return absolute URL of current file/folder
var url = anyEntry.toURL();
// url = filesystem:http://localhost/...