Finder别名不能在Mac上用node.js识别为符号链接

我正在运行一个nodewebkit应用程序,我想search一个文件夹的别名。

以下代码正在工作,但不能将文件夹别名或文件别名识别为符号链接。

我错在哪里?

var path = '/Users/test/Desktop/testfolder'; var fs = require('fs'); fs.readdir(path, function(err, files) { if (err) return; files.forEach(function(f) { var newPath = path + '/' + f; console.log("looking for "+ newPath +" symlink: "+fs.lstatSync(path).isSymbolicLink()); fs.lstat(newPath, function(err, stats){ if(err){ console.log(err); } if(stats.isFile()){ console.log('is file mofo',f); } if(stats.isDirectory()){ console.log('is Directory mofo',f); } if(stats.isSymbolicLink()){ console.log('is symbolic link'); } }); }); }); 

在OS X上的Finder别名在技​​术上与符号链接不同。

从文件系统的angular度来看,它们是常规文件,只有Finder本身和OS X特定的API才能处理它们 – Node.js没有内置的API。

如果调用shell (这将是缓慢的)是一个选项,你可以尝试以下方法:

 function isFinderAlias(path) { var contentType = require('child_process') .execFileSync('mdls', [ '-raw', '-name', 'kMDItemContentType', path ], { encoding: 'utf8' }) return contentType === 'com.apple.alias-file' } 

对于一个swift的方式来解决一个Finder别名到其目标path ,看到这个答案 。

Interesting Posts