英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论