var File = {
/**
- * @scope File
+ * @static
+ * @type {String} File seperator. (should be dynamic....)
*/
return s;
},
+ /**
+ * Get the base name of a path.
+ * @param {String} path
+ * @returns {String} basename
+ */
+ basename : function(path)
+ {
+ return path.split(File.SEPARATOR).pop();
+ },
+
+ /**
+ * Get the directory name of a path. (could use Glib really)
+ * @param {String} path
+ * @returns {String} dirname
+ */
+ dirname : function(path)
+ {
+ var r = path.split(File.SEPARATOR)
+ r.pop();
+ return r.join(File.SEPARATOR);
+ },
+
+
/**
* Join a path with the Correct File seperator (unix only at present...)
* Takes a variable number of arguments, and joins them together.
},
/**
- * write a file
- * @arg path {String} File to write to
- * @arg string {String} Contents of file.
+ * write a string to file
+ * @param {String} pathFile to write to
+ * @param {String} string Contents of file.
*
*/
write : function (path, string) {
data_out.close(null);
},
/**
- * append
- * @arg path {String} File to write to
- * @arg string {String} string to append to file.
+ * append a string to a file
+ * @param {String} path File to write to
+ * @param {String} string string to append to file.
*
*/
append : function (path, string) {
data_out.close(null);
},
/**
- * remove
* Delete a file.
- * @arg path {String} File to remove
- *
- *
+ * @param {String} path File to remove
*/
remove : function (path)
{
return f['delete']();
},
/**
- * silentRecursiveCopy
* copy files recursively from fromDir, silently ignore them if they already exist in toDir
* unless you select overwrite..
- * @arg {String} src source path
- * @arg {String} dest destination path
- * @arg {Gio.FileCopyFlags} options (optional) - use Gio.FileCopyFlags.OVERWRITE to
+ * @param {String} src source path
+ * @param {String} dest destination path
+ * @param {Gio.FileCopyFlags} options (optional) - use Gio.FileCopyFlags.OVERWRITE to
* otherwise they will not be copied
*
*/
},
/**
- * mkdir
* make a directory..
- * @arg {String} dstPath directory to make
+ * @param {String} dstPath directory to make
*/
mkdir : function (destPath) {
var dest = Gio.file_new_for_path(String(destPath));
return dest.make_directory(null, null);
},
/**
- * copyFile
- * @arg {String} src source path
- * @arg {String} dest destination path
- * @arg {Gio.FileCopyFlags} options (optional) - use Gio.FileCopyFlags.OVERWRITE to .. overwrite..
+ * copy a File
+ * @param {String} src source path
+ * @param {String} dest destination path
+ * @param {Gio.FileCopyFlags} options (optional) - use Gio.FileCopyFlags.OVERWRITE to .. overwrite..
*
*/
copyFile : function (srcPath, destPath, opts) {
// can be nulled, but not according to the GIR file
return src.copy(dest, opts);
},
-
+ /**
+ * recursively list files in a directory.
+ * @param {String} path The directory
+ * @return {Array} list of files (with full path?)
+ */
recursiveListing : function (dir) {
function recursiveListingInternal(prefix, listing, dir) {
- var entries = File.list(dir);
- var next, fullPath;
-
- for (var index in entries) {
- next = entries[index];
- fullPath = File.join(prefix, dir, next);
-
- if (File.isDirectory(fullPath)) {
- listing.push(next);
- listing = listing.concat(recursiveListingInternal(next, [], fullPath));
- }
- else {
- if (prefix) {
- next = File.join(prefix, next);
+ var entries = File.list(dir);
+ var next, fullPath;
+
+ for (var index in entries) {
+ next = entries[index];
+ fullPath = File.join(prefix, dir, next);
+
+ if (File.isDirectory(fullPath)) {
+ listing.push(next);
+ listing = listing.concat(recursiveListingInternal(next, [], fullPath));
+ }
+ else {
+ if (prefix) {
+ next = File.join(prefix, next);
+ }
+ listing.push(next);
}
- listing.push(next);
}
- }
-
- return listing;
+
+ return listing;
}
return recursiveListingInternal('', [], dir);