node.js - How to parse in javascript list of files which are response on ls command -
I am using the ssh2
library to run the remote server / shell command All the files in the specific directory should be listed. How to parse the javascript list of files? I have a string-like response on command ls
but it is separated from '' but I can not parse, because in the name '' can also be I ls -al
but I do not know that it parses all the chars in the same format. To get the list of remote files in JavaScript, what command for the shell
output an entry You can use ls-1
to force you to copy per line (filenames are therefore separated by \ n
.).
-1 (numerical digit 'one'.) Output to be an entry for each line. This is the default when the output is not on the terminal.
It works in most cases, but not in all. For more information about why the output of ls
should not be parsed, see.
The main point is that there is no implementation of \ 0
character, and ls
in the Unix filename that will allow you to type \ 0
Allows to separate filenames by \ n
instead.
However, ssh2
supports SFTP, so there is a better way to list files in one directory:
var connection = Required ('ssh2'); Var c = new connection (); C.on ('ready', function () {c.sftp (function (err, sftp) {If (mistake) becomes a mistake; sftp.opendir ('foo', function readdir (err, handle) {if ( Throw err; // reads some directory entries, but all the pirate.reading (handle, function (mistake, list) {If throwing (mistake) is wrong; // All files are listed, if (list === false) Sftp.close (handle, function) {If (mistake) becomes a mistake; sftp.end ();}); return;} console.dir (list);})}}); });}); See the ssh2
for the document of readdir
method for the GitHub page:
Comments
Post a Comment