PhantomJS - 列表



list 方法返回目錄中存在的所有檔案。

語法

其語法如下 −

var fs = require('fs'); 
fs.list(path); 

範例

以下範例顯示 list 方法的用法。

命令 − phantomjs list.js C:\phantomjs\

var fs = require('fs'); 
var system = require('system'); 
var path = system.args[1]; 

if (fs.isDirectory(path)) { 
   console.log(fs.list(path)); 
} 
phantom.exit(); 

上述程式會產生以下 輸出

.,..,bin,ChangeLog,examples,LICENSE.BSD,README.md,third-party.txt

輸出顯示 PhantomJS 目錄中存在的所有檔案。

phantomjs_file_system_module_methods.htm
廣告
© . All rights reserved.