| 
									
										
										
										
											2011-02-03 23:57:11 -07:00
										 |  |  | #!/usr/bin/env node
 | 
					
						
							|  |  |  | (function () { | 
					
						
							|  |  |  |   "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-28 07:57:02 -06:00
										 |  |  |   var walk = require('walk') | 
					
						
							|  |  |  |     , count = 0 | 
					
						
							|  |  |  |     , emitter | 
					
						
							|  |  |  |     , saneCount = 0 | 
					
						
							|  |  |  |     ; | 
					
						
							| 
									
										
										
										
											2011-02-03 23:57:11 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   function sort(a,b) { | 
					
						
							|  |  |  |     a= a.toLowerCase(); | 
					
						
							|  |  |  |     b= b.toLowerCase(); | 
					
						
							|  |  |  |     if (a > b) return -1; | 
					
						
							|  |  |  |     if (a < b) return  1; | 
					
						
							| 
									
										
										
										
											2011-02-04 00:14:19 -07:00
										 |  |  |     return  0; | 
					
						
							| 
									
										
										
										
											2011-02-03 23:57:11 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   process.argv.forEach(function(startpath, index) { | 
					
						
							|  |  |  |     if (index > 1) { | 
					
						
							| 
									
										
										
										
											2011-07-28 07:57:02 -06:00
										 |  |  |       emitter = walk.walk(startpath); | 
					
						
							| 
									
										
										
										
											2011-02-03 23:57:11 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Non-`stat`ed Nodes
 | 
					
						
							|  |  |  |       emitter.on('name', function (path, file, stat) { | 
					
						
							|  |  |  |         saneCount += 1; | 
					
						
							|  |  |  |         //console.log( ["[", count, "] ", path, '/', file].join('') )
 | 
					
						
							| 
									
										
										
										
											2011-02-04 00:16:29 -07:00
										 |  |  |         //console.log( [path, '/', file].join('') )
 | 
					
						
							| 
									
										
										
										
											2011-02-03 23:57:11 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |       emitter.on('names', function (path, files, stats) { | 
					
						
							|  |  |  |         files.sort(sort); | 
					
						
							|  |  |  |         //console.log('sort: ' + files.join(' ; '));
 | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 00:14:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-03 23:57:11 -07:00
										 |  |  |   // Single `stat`ed Nodes
 | 
					
						
							|  |  |  |       emitter.on('error', function (path, err, next) { | 
					
						
							| 
									
										
										
										
											2011-02-04 00:14:19 -07:00
										 |  |  |         next() | 
					
						
							| 
									
										
										
										
											2011-02-03 23:57:11 -07:00
										 |  |  |         // ignore
 | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       emitter.on('directoryError', function (path, stats, next) { | 
					
						
							|  |  |  |         next(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       emitter.on('nodeError', function (path, stats, next) { | 
					
						
							|  |  |  |         next(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       /* | 
					
						
							|  |  |  |       emitter.on('node', function (path, stat, next) { | 
					
						
							|  |  |  |         count += 1; | 
					
						
							|  |  |  |         console.log( [path, '/', stat.name].join('') ) | 
					
						
							|  |  |  |         //console.log( ["[", count, "] ", path, '/', stat.name].join('') )
 | 
					
						
							|  |  |  |         next(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       */ | 
					
						
							|  |  |  |       emitter.on('file', function (path, stat, next) { | 
					
						
							|  |  |  |         count += 1; | 
					
						
							|  |  |  |         console.log( [path, '/', stat.name].join('') ) | 
					
						
							|  |  |  |         //console.log( ["[", count, "] ", path, '/', stat.name].join('') )
 | 
					
						
							|  |  |  |         next(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       emitter.on('directory', function (path, stat, next) { | 
					
						
							|  |  |  |         count += 1; | 
					
						
							|  |  |  |         console.log( [path, '/', stat.name].join('') ) | 
					
						
							|  |  |  |         next(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       emitter.on('symbolicLink', function (path, stat, next) { | 
					
						
							|  |  |  |         count += 1; | 
					
						
							|  |  |  |         console.log( [path, '/', stat.name].join('') ) | 
					
						
							|  |  |  |         next(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       /* | 
					
						
							|  |  |  |       emitter.on('blockDevice', function (path, stat, next) { | 
					
						
							|  |  |  |         next(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       emitter.on('characterDevice', function (path, stat, next) { | 
					
						
							|  |  |  |         next(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       emitter.on('FIFO', function (path, stat, next) { | 
					
						
							|  |  |  |         next(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       emitter.on('socket', function (path, stat, next) { | 
					
						
							|  |  |  |         next(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 00:14:19 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-03 23:57:11 -07:00
										 |  |  |     // Grouped `stat`ed Nodes
 | 
					
						
							|  |  |  |       emitter.on('errors', function (path, stats, next) { | 
					
						
							|  |  |  |         next(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       /* | 
					
						
							|  |  |  |       emitter.on('nodes', function (path, stats, next) { | 
					
						
							|  |  |  |         next(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       */ | 
					
						
							|  |  |  |       emitter.on('files', function (path, stats, next) { | 
					
						
							|  |  |  |         next(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       emitter.on('directories', function (path, stats, next) { | 
					
						
							|  |  |  |         //delete stats[1];
 | 
					
						
							|  |  |  |         next(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       emitter.on('symbolicLinks', function (path, stats, next) { | 
					
						
							|  |  |  |         next(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       /* | 
					
						
							|  |  |  |       emitter.on('blockDevices', function (path, stats, next) { | 
					
						
							|  |  |  |         next(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       emitter.on('characterDevices', function (path, stats, next) { | 
					
						
							|  |  |  |         next(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       emitter.on('FIFOs', function (path, stats, next) { | 
					
						
							|  |  |  |         next(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       emitter.on('sockets', function (path, stats, next) { | 
					
						
							|  |  |  |         next(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 00:14:19 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-03 23:57:11 -07:00
										 |  |  |     // The end of all things
 | 
					
						
							|  |  |  |       emitter.on('end', function () { | 
					
						
							|  |  |  |         console.log("The eagle has landed. [" + count + " == " + saneCount + "]"); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }()); |