查找以...开头的最新文件 [英] Find newest file starting with ...
问题描述
嗨大家好,
我有一个包含数千个PDF的目录。如果客户ID,所有这些都有一个文件名前缀。 ABC123_0001.pdf,ABC123_0002.pdf .... XYZ123_0001.pdf,XYZ132_0002。
I have a directory with thousands of PDFs. All of which have a filename prefix if the customer ID. ABC123_0001.pdf, ABC123_0002.pdf....XYZ123_0001.pdf, XYZ132_0002.
我需要能够在目录中找到特定客户的最新文件。
I need to be able to locate the newest file in the directory for a particular customer.
所以说客户ID是MAR123,最新文件是MAR123_0059,然后我想使用客户ID作为参数来获取最新文件。
So say the customer ID was MAR123 and the newest file was MAR123_0059, then I want to use the customer ID as an argument to get the most recent file.
不知道从哪里开始。
任何想法???
John
jppnn
推荐答案
我的文件在目录,然后您可以将所有文件名加载到一个数组
I the files are in a directory, then you can load all the file names into an array
https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.getfiles? view = netframework-4.7.2
https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.getfiles?view=netframework-4.7.2
然后你可以使用Linq Contains(),StartsWith()和EndsWith()函数。
Then you can use Linq Contains(), StartsWith() and EndsWith() functions.
http://www.dotnetlearners.com/linq/linq-to-string-array-with-example.aspx
http://www.dotnetlearners.com/linq/linq-to-string-array-with-example.aspx
It可能会让你进入球场。
It may get you in the ballpark.
这篇关于查找以...开头的最新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!