summaryrefslogtreecommitdiffstats
path: root/lib/utils/fs.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils/fs.js')
-rw-r--r--lib/utils/fs.js22
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/utils/fs.js b/lib/utils/fs.js
index 8d8c189..e434953 100644
--- a/lib/utils/fs.js
+++ b/lib/utils/fs.js
@@ -43,9 +43,27 @@ var fsUtils = {
},
existsSync: fs.existsSync.bind(fs),
readFileSync: fs.readFileSync.bind(fs),
- clean: cleanFolder
+ clean: cleanFolder,
+ getUniqueFilename: getUniqueFilename
}
+// Find a filename available
+function getUniqueFilename(base) {
+ var ext = path.extname(base);
+ base = path.join(path.dirname(base), path.basename(base, ext));
+
+ var filename = base+ext;
+
+ var i = 0;
+ while (1) {
+ if (!fs.existsSync(filename)) break;
+ filename = base+"_"+i+ext;
+ i = i + 1;
+ }
+
+ return filename;
+};
+
// List files in a directory
function listFiles(root, options) {
@@ -112,7 +130,7 @@ function cleanFolder(root) {
var _file = path.join(root, file);
d.notify({
- i: i,
+ i: i+1,
count: files.length,
file: _file
});