DIV CSS 佈局教程網

Node.js 中 fs.symlink 方法詳解與使用教學
編輯:關於JavaScript     

方法說明

用來建立符號鏈接(symbolic link),也就是類似 Unix 的 symlink。

語法

fs.symlink(srcpath, dstpath, [type], [callback(err)])

此方式屬於 fs 模組,使用前必須先引入:var fs = require("fs")

參數說明

srcpath:來源目錄或檔案的路徑。

dstpath:存放鏈接的路徑,預設為目前工作目錄。

type:預設值為 'file',可選值為 'dir'、'file' 或 'junction'。此參數僅在 Windows 上有意義,其他平台會忽略。

callback:回調函式,接收 err 異常參數。

注意

Windows 的 junction 類型要求 dstpath 必須是絕對路徑;使用 'junction' 時,目標參數會自動被正規化為絕對路徑。

原始碼

可以注意到 callback 是從 arguments 的最後一個位置取出,因此 type 參數可以省略。

fs.symlink = function(destination, path, type_, callback) {
  var type = (util.isString(type_) ? type_ : null);
  var callback = makeCallback(arguments[arguments.length - 1]);
  if (!nullCheck(destination, callback)) return;
  if (!nullCheck(path, callback)) return;
  binding.symlink(preprocessSymlinkDestination(destination, type),
                 pathModule._makeLong(path),
                 type,
                 callback);
};
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved