【问题标题】:get modified date of subfolder within folder获取文件夹内子文件夹的修改日期
【发布时间】:2017-11-13 13:04:55
【问题描述】:

大约有 1000 个共享文件夹,我需要找出它们最后一次修改的时间。 因此,这些共享文件夹包含子文件夹,用户可以修改这些子文件夹中的数据。

我有一个脚本可以获取父文件夹的最后修改日期,但它没有提供正确的数据。

$CSVFilePath = Get-Content "C:\RA\main.txt"
$outputsss = "C:\RA\output.csv"
foreach ($fileName in $CSVFilePath) {
    echo $fileName;
    if (Test-Path $fileName) {
        $d = Get-ItemProperty -Path $fileName -Name LastWriteTime
        $times = $fileName + " - " + $d.LastWriteTime
        $times
    }
    $times | Out-File $outputsss -Encoding utf8 -Append
    #Get-Content $filename | Out-File $outputsss -Encoding utf8 -Append
}

有什么方法可以获取共享位置的最后修改日期时间?

【问题讨论】:

  • 什么是不正确的数据和您期望的数据?
  • @Manu 例如,我有 10 个文件夹,父名称是 A,在父目录中,我还有其他 9 个文件夹,在这 9 个文件夹中可能还有更多文件夹。如果其中任何一个得到更新,那么我如何获得修改日期。因为如果我检查 A 的修改日期,那么它不会显示正确的日期。
  • 我怀疑它没有显示正确的日期,尽管它可能没有显示您期望的日期。文件夹最后修改时间的更新不能递归工作。 Related。 Also related.
  • @AnsgarWiechers 我发现了一个可以在这种情况下提供帮助的问题。 stackoverflow.com/questions/9675658/… 但无法正常工作。你能看看吗。

标签: powershell


【解决方案1】:

我尝试了多次,下面是帮助我的脚本。我需要验证它,因为它仍在运行。

$CSVFilePath = Get-Content "C:\RA\main.txt"
$outputsss = "C:\RA\output.csv"
foreach($fileName in $CSVFilePath)
{
echo $fileName;
If (Test-Path $fileName) {

$latest = Get-ChildItem -Recurse  -Path $fileName | Sort-Object LastAccessTime -Descending | Select-Object -First 1
$latest.LastWriteTime

    #$d = Get-ItemProperty -path $fileName -Name LastWriteTime
    $times = $fileName + " - " + $latest.LastWriteTime
$times
    }
$times |Out-File $outputsss -Encoding utf8 -append

}

我希望它对某人有价值。

【讨论】:

    猜你喜欢
    • 2011-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-12
    • 2013-01-12
    • 2021-10-25
    • 2013-02-18
    • 2021-05-27
    相关资源
    最近更新 更多