WinSCP Session.EnumerateRemoteFiles 不支持带有时间约束的掩码。

huangapple go评论80阅读模式
英文:

WinSCP Session.EnumerateRemoteFiles does not work with mask with time constraint

问题

这个掩码有效。计数返回 9018。

var filesCount1 =
    session.EnumerateRemoteFiles(
        serverPath, "*.xml", WinSCP.EnumerationOptions.None).Count();

这个掩码无效。计数返回 0。

var filesCount2 =
    session.EnumerateRemoteFiles(
        serverPath, "*.xml>24HS", WinSCP.EnumerationOptions.None).Count();

我该如何修复它?我想逐个获取文件,因为我需要在下载之前进行一些验证。

英文:

I'm trying to get the files from the SFTP server. The goal is, to get files newer than 24 hours.

This mask works. The count returns 9018.

var filesCount1 =
    session.EnumerateRemoteFiles(
        serverPath, "*.xml", WinSCP.EnumerationOptions.None).Count();

This mask does not work. The count returns 0.

var filesCount2 =
    session.EnumerateRemoteFiles(
        serverPath, "*.xml>24HS", WinSCP.EnumerationOptions.None).Count();

How can I fix it? I want to get file one by one, because I need to do some validation before the download.

答案1

得分: 1

如记录所示,Session.EnumerateRemoteFiles 仅支持简单的Windows通配符:
https://winscp.net/eng/docs/library_session_enumerateremotefiles#parameters

但您可以简单地过滤方法返回的枚举结果:

DateTime limit = DateTime.Now.AddDays(-1);
var filesCount1 = 
    session.EnumerateRemoteFiles(
        serverPath, "*.xml", WinSCP.EnumerationOptions.None)
    .Where(file => file.LastWriteTime > limit)
    .Count();

请注意,这计算的是“比24小时新”的文件,如您所要求的。这并不是>24HS 文件掩码的含义。所以我不太确定您到底需要什么。

英文:

As documented, Session.EnumerateRemoteFiles supports simple Windows wildcards only:
https://winscp.net/eng/docs/library_session_enumerateremotefiles#parameters


But you can simply filter the enumeration that the method returns:

DateTime limit = DateTime.Now.AddDays(-1);
var filesCount1 = 
    session.EnumerateRemoteFiles(
        serverPath, "*.xml", WinSCP.EnumerationOptions.None)
    .Where(file => file.LastWriteTime > limit)
    .Count();

Note that this counts "files newer than 24 hours", as you asked for. What is not what file mask >24HS means. So I'm not sure what exactly are you after.

huangapple
  • 本文由 发表于 2023年2月26日 23:01:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/75572850.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定