Skip to content

TagSpaces is an offline, open source, document manager with tagging support

adding listSubDirectories method

Iliane01225b46edd
diff --git a/data/js/ioapi.chrome.js b/data/js/ioapi.chrome.js
index 6a74c9f5f..850fb4668 100644
--- a/data/js/ioapi.chrome.js
+++ b/data/js/ioapi.chrome.js
@@ -48,7 +48,7 @@ IO-API
try {
var dirList = nativeIO.getDirEntries(dirPath);
for (var i=0; i < dirList.length; i++) {
- var path = dirPath+getDirseparator()+dirList[i];
+ var path = dirPath+TSCORE.dirSeparator+dirList[i];
var isDir = nativeIO.isDirectory(path);
var fileSize = 0;
var lastDateModified = 0;
@@ -78,14 +78,14 @@ IO-API
function generateDirectoryTree(dirPath) {
try {
var tree = {};
- tree["name"] = dirPath.substring(dirPath.lastIndexOf(getDirseparator()) + 1, dirPath.length);
+ tree["name"] = dirPath.substring(dirPath.lastIndexOf(TSCORE.dirSeparator) + 1, dirPath.length);
tree["type"] = false;
tree["lmdt"] = 0;
tree["path"] = dirPath;
tree["children"] = [];
var dirList = nativeIO.getDirEntries(dirPath);
for (var i=0; i < dirList.length; i++) {
- var path = dirPath+getDirseparator()+dirList[i];
+ var path = dirPath+TSCORE.dirSeparator+dirList[i];
var isDir = nativeIO.isDirectory(path);
var fileSize = 0;
var lastDateModified = 0;
@@ -115,14 +115,6 @@ IO-API
return (navigator.platform == 'Win32');
}
- function getDirseparator() {
- if(isWindows()) {
- return "\\";
- } else {
- return "/";
- }
- }
-
var checkNewVersion = function() {
console.log("Checking for new version...");
var cVer = TSCORE.Config.DefaultSettings["appVersion"]+"."+TSCORE.Config.DefaultSettings["appBuild"];
@@ -170,7 +162,7 @@ IO-API
var dirList = nativeIO.getDirEntries(dirPath);
var anotatedDirList = [];
for (var i=0; i < dirList.length; i++) {
- var path = dirPath+getDirseparator()+dirList[i];
+ var path = dirPath+TSCORE.dirSeparator+dirList[i];
var isDir = nativeIO.isDirectory(path);
var fileSize = 0;
var lastDateModified = 0;
@@ -194,6 +186,29 @@ IO-API
console.log("Directory does not exists.");
}
};
+
+ var listSubDirectories = function(dirPath) {
+ console.log("Listing sub directories: "+dirPath);
+ TSCORE.showLoadingAnimation();
+ if(nativeIO.isDirectory(dirPath)) {
+ var dirList = nativeIO.getDirEntries(dirPath);
+ var anotatedDirList = [];
+ for (var i=0; i < dirList.length; i++) {
+ var path = dirPath+TSCORE.dirSeparator+dirList[i];
+ var isDir = nativeIO.isDirectory(path);
+ if(isDir) {
+ anotatedDirList.push({
+ "name": dirList[i],
+ "path": path
+ });
+ }
+ }
+ TSPOSTIO.listSubDirectories(anotatedDirList);
+ } else {
+ //TSPOSTIO.errorOpeningPath();
+ console.log("Directory does not exists.");
+ }
+ };
var deleteElement = function(path) {
console.log("Deleting: "+path);
@@ -370,6 +385,7 @@ IO-API
exports.loadTextFile = loadTextFile;
exports.saveTextFile = saveTextFile;
exports.listDirectory = listDirectory;
+ exports.listSubDirectories = listSubDirectories;
exports.deleteElement = deleteElement;
exports.createDirectoryIndex = createDirectoryIndex;
exports.createDirectoryTree = createDirectoryTree;
diff --git a/data/js/ioapi.cordova.js b/data/js/ioapi.cordova.js
index 2b89706dd..490352fce 100644
--- a/data/js/ioapi.cordova.js
+++ b/data/js/ioapi.cordova.js
@@ -6,8 +6,7 @@ define(function (require, exports, module) {
console.log("Loading ioapi.cordova.js..");
- var TSCORE = require("tscore");
-
+ var TSCORE = require("tscore");
var TSPOSTIO = require("tspostioapi");
var fsRoot = undefined;
@@ -126,19 +125,7 @@ define(function (require, exports, module) {
//TSCORE.showAlertDialog("Creating directory tree is not supported on Android yet.");
};
-
- function isWindows() {
- return (navigator.platform == 'Win32');
- }
-
- function getDirseparator() {
- if(isWindows()) {
- return "\\";
- } else {
- return "/";
- }
- }
-
+
function normalizePath(path) {
if(path.indexOf(fsRoot.fullPath) >= 0) {
path = path.substring(fsRoot.fullPath.length+1, path.length);
@@ -162,6 +149,45 @@ define(function (require, exports, module) {
;
};
+ var listSubDirectories = function (dirPath) {
+ // directory path format DCIM/Camera/ !
+ dirPath = dirPath+"/"; // TODO make it platform independent
+ dirPath = normalizePath(dirPath);
+ console.log("Listing sub directories of: " + dirPath);
+ TSCORE.showLoadingAnimation();
+
+ fsRoot.getDirectory(dirPath, {create: false, exclusive: false},
+ function (dirEntry) {
+ var directoryReader = dirEntry.createReader();
+
+ // Get a list of all the entries in the directory
+ directoryReader.readEntries(
+ function (entries) {
+ var i;
+ var anotatedDirList = [];
+ for (i = 0; i < entries.length; i++) {
+ if(entries[i].isDirectory){
+ anotatedDirList.push({
+ "name": entries[i].name,
+ "path": entries[i].fullPath
+ });
+ }
+ }
+ //console.log("Dir content: " + JSON.stringify(entries));
+ TSPOSTIO.listSubDirectories(anotatedDirList);
+ }, function (error) { // error get file system
+ //TSPOSTIO.errorOpeningPath();
+ console.log("Listing sub directories failed: " + error.code);
+ }
+ );
+ },
+ function (error) {
+ //TSPOSTIO.errorOpeningPath();
+ console.log("Getting sub directories of : "+dirPath+" failed: " + error.code);
+ }
+ );
+ };
+
var listDirectory = function (dirPath) {
TSCORE.showLoadingAnimation();
// directory path format DCIM/Camera/ !
@@ -420,6 +446,7 @@ define(function (require, exports, module) {
exports.loadTextFile = loadTextFile;
exports.saveTextFile = saveTextFile;
exports.listDirectory = listDirectory;
+ exports.listSubDirectories = listSubDirectories;
exports.deleteElement = deleteElement;
exports.createDirectoryIndex = createDirectoryIndex;
exports.createDirectoryTree = createDirectoryTree;