Powershell-获取最后修改的文件的父目录名称

我有几个文件夹,并且每个文件夹中都有一个Log文件夹和日志文件。 仅该文件夹之一会修改其日志文件。而且我需要检索其顶级父目录名称。

I can't use Sort-Object LastWriteTime because whenever the log gets updated - only the log file gets its last modified time updated. The Log and the top parent folder doesn't have their lastwritetime updated at all.

我怎样才能做到这一点?

Folder1\Log\filename1.log
Folder2\Log\filename3.log -> Assume this is the latest one that got its log file updated.
Folder3\Log\filename5.log
Folder4\Log\filename2.log
Folder5\Log\filename6.log

我想获取“ Folder2”作为输出

评论