我想计算一个远程文件夹中的所有文件。我发现“官方” WinSCP脚本列出了文件夹中的每个文件。但是我想算一下,然后将结果保存到变量中。最简单的方法是什么?
let isPlayer = false;
if (response) {
const roleNames = Object.values(response["Roles"]);
const playerFound = roleNames.find(names => names.includes('Player'))
isPlayer = !!playerFound;
}
答案 0 :(得分:1)
session.EnumerateReportFiles
请参见How to get the files of remote directory using a pattern with C# and WinSCP
$files =
$session.EnumerateRemoteFiles(
$remotePath, $wildcard, [WinSCP.EnumerationOptions]::None)
var filecount = $files.Count();
答案 1 :(得分:1)
使用EnumerateRemoteFiles并在获得主父目录的所有文件信息后进行计数。
foreach (RemoteFileInfo fileInfo in directory.Files)
{
Console.WriteLine("{0} with size {1}, permissions {2} and last modification at {3}",
fileInfo.Name, fileInfo.Length, fileInfo.FilePermissions,
fileInfo.LastWriteTime);
Console.WriteLine(fileInfo.FullName);
string FilePath = fileInfo.FullName;
if (session.FileExists(FilePath))
{
Console.WriteLine("Folder exists");
var a = session.EnumerateRemoteFiles(FilePath, null,
EnumerationOptions.AllDirectories);
Console.WriteLine(a.Count());
}
}