binarykitchen / find-remove

recursively finds files by filter options from a start directory onwards and deletes these. useful if you want to clean up a directory in your node.js app.
https://npmjs.org/package/find-remove
61 stars 19 forks source link

remove from windows dir ? #5

Open irom77 opened 9 years ago

irom77 commented 9 years ago

How do I put absolute Windows path ?

binarykitchen commented 9 years ago

Haven't tested with Windows yet. But could you try this and and paste the output here?

var result = findRemoveSync('c:\Temp', {test: true});
console.log(result);

If you use a newer Window version, probably try using this path instead: C:\Users\User Name\AppData\Local\Temp (%USERPROFILE%\AppData\Local\Temp)

Not sure here. Maybe some work is needed here to make find-remove truly Windows-compatible.

irom77 commented 9 years ago

See below. Not sure why I have to use specific directories. Isn't your code suppose to work on any give directory ?

var result = findRemoveSync('c:\Temp', {test: true});
console.log(result);
var result = findRemoveSync('C:\Users\IrekRomaniuk\AppData\Local\Temp', {test: true});
console.log(result);

and the output is :

[] [] Process finished with exit code 0

irom77 commented 9 years ago

oh sorry, I just noticed it works fine on windows..what was not working is age.seconds argument, doesn't remove files

var result = findRemoveSync('c:\Temp', {age: {seconds: 3600}, extensions: '.jpg'});
console.log(result);

[] Process finished with exit code 0

binarykitchen commented 9 years ago

@irom77 have you verified the age of these jpg files? you sure they older than one hour?

irom77 commented 9 years ago

See below

D:\ftproot\nodejs>more repstat2.js
var findRemoveSync = require('find-remove');
var result = findRemoveSync('D:\ftproot\mds_backup2', {test: true});
console.log(result);

var result = findRemoveSync('D:\ftproot\mds_backup2', {age: {seconds: 172800},extensions: '.txt'});

D:\ftproot\nodejs>node repstat2.js
[]

D:\ftproot\nodejs>dir d:\ftproot\mds_backup2\*.txt
 Volume in drive D is Data
 Volume Serial Number is 104C-9C39

 Directory of d:\ftproot\mds_backup2

04/20/2015  07:36 AM            67,402 kernel_debug-MAR-VSX-015.txt
12/16/2013  09:50 AM        11,019,808 kernel_debug2.txt
07/17/2015  11:51 AM                 0 new.txt
12/06/2014  04:00 PM            27,696 pinglist-all.txt
11/22/2014  05:45 PM            12,585 pinglist-MAL-up.txt
11/23/2014  03:49 PM            12,447 pinglist-MAL2-up.txt
11/23/2014  04:43 PM            12,487 pinglist-MAL3-up.txt
11/22/2014  05:56 PM             3,399 pinglist-WAL-down.txt
06/08/2015  02:36 PM           290,426 rep-ike.txt
06/15/2015  03:15 PM           110,825 rep-lsm.txt
09/17/2011  06:26 AM         3,506,759 tcpdumpexternal.txt
01/24/2014  11:30 PM            84,057 tunneldrop.txt
03/19/2015  11:23 AM            13,167 WAL-NEW-VSX-01.txt
03/19/2015  12:27 PM            13,167 WAL-NEW-VSX-02.txt
              14 File(s)     15,174,225 bytes
               0 Dir(s)  26,791,469,056 bytes free

D:\ftproot\nodejs>
binarykitchen commented 9 years ago

both findRemoveSync() calls do not have the same parameters, hence you cannot compare like that.

try this:

var result = findRemoveSync('D:\ftproot\mds_backup2', {test: true, age: {seconds: 172800},extensions: '.txt'});
console.log(result);

and share the output here altogether with the contents of that directory. then we can start investigating the problem.

(be careful, if you do a findRemoveSync('D:\ftproot\mds_backup2'); it will delete everything in it)

irom77 commented 9 years ago

Here it is: D:\ftproot\nodejs>more repstat2.js var findRemoveSync = require('find-remove'); var result = findRemoveSync('D:\ftproot\mds_backup2', {test: true, age: {seconds : 172800},extensions: '.txt'}); console.log(result);

D:\ftproot\nodejs>node repstat2.js []

D:\ftproot\nodejs>dir d:\ftproot\mds_backup2*.txt Volume in drive D is Data Volume Serial Number is 104C-9C39

Directory of d:\ftproot\mds_backup2

04/20/2015 07:36 AM 67,402 kernel_debug-MAR-VSX-015.txt 12/16/2013 09:50 AM 11,019,808 kernel_debug2.txt 07/17/2015 11:51 AM 0 new.txt 07/17/2015 12:32 PM 0 new2.txt 12/06/2014 04:00 PM 27,696 pinglist-all.txt 11/22/2014 05:45 PM 12,585 pinglist-MAL-up.txt 11/23/2014 03:49 PM 12,447 pinglist-MAL2-up.txt 11/23/2014 04:43 PM 12,487 pinglist-MAL3-up.txt 11/22/2014 05:56 PM 3,399 pinglist-WAL-down.txt 06/08/2015 02:36 PM 290,426 rep-ike.txt 06/15/2015 03:15 PM 110,825 rep-lsm.txt 09/17/2011 06:26 AM 3,506,759 tcpdumpexternal.txt 01/24/2014 11:30 PM 84,057 tunneldrop.txt 03/19/2015 11:23 AM 13,167 WAL-NEW-VSX-01.txt 03/19/2015 12:27 PM 13,167 WAL-NEW-VSX-02.txt 15 File(s) 15,174,225 bytes 0 Dir(s) 26,770,358,272 bytes free

D:\ftproot\nodejs>

binarykitchen commented 9 years ago

Right, that's evidence that something is wrong.

It's unfortunate that I have no Windows machine here to reproduce and fix this.

If I were you, I would add some console.log(...) lines in the source code and try again. For example here, inside the important isOlder() function: https://github.com/binarykitchen/find-remove/blob/master/find-remove.js#L126

add console.log('isOlder:', path, ctime, ageSeconds, now)

When the path for the file kernel_debug2.txt appears, paste the console output here.