Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 修改Powershell脚本以修改';上次修改日期';选定目录中的子文件夹数目_Windows_Powershell - Fatal编程技术网

Windows 修改Powershell脚本以修改';上次修改日期';选定目录中的子文件夹数目

Windows 修改Powershell脚本以修改';上次修改日期';选定目录中的子文件夹数目,windows,powershell,Windows,Powershell,我已经创建了下面的脚本,该脚本已经过测试并成功运行,用于修改所选文件夹中包含的所有文件的“上次修改日期” $a = Get-Date "22/11/2012 10:00 AM" $b = Get-ChildItem "C:\MyFiles" foreach ($i in $b) { $i.LastWriteTime = $a $a = $a.AddMinutes(1) } $b 我只是在寻找一些帮助来修改这个脚本,以包括所选文件夹中的所有子文件夹/文件,因为我目前

我已经创建了下面的脚本,该脚本已经过测试并成功运行,用于修改所选文件夹中包含的所有文件的“上次修改日期”

$a = Get-Date "22/11/2012 10:00 AM"

$b = Get-ChildItem "C:\MyFiles"

foreach ($i in $b)
{
    $i.LastWriteTime = $a
    $a = $a.AddMinutes(1)    
}

$b
我只是在寻找一些帮助来修改这个脚本,以包括所选文件夹中的所有子文件夹/文件,因为我目前必须手动修改这个脚本,以更改“C:\MyFiles”子文件夹中的日期。。例如“C:\MyFiles\A”、“C:\MyFiles\B”。。等等

此外。。我还想知道如何删除行“$a=Get Date”22/11/2012 10:00 AM”,以便它自动将日期设置为今天,而不必手动输入日期。

像这样吗

    $a = get-date
    $b = Get-ChildItem "C:\MyFiles" -recurse | ? { !$_.psiscontainer }
    foreach ($i in $b)
    {
        $i.LastWriteTime = $a 
        $a = $a.AddMinutes(1)    
    }

    $b
或者,如果不需要在每个文件后添加一分钟:

     $dir = read-host "Insert path"
     $b = Get-ChildItem $dir -recurse | ? { !$_.psiscontainer }
    foreach ($i in $b)
    {
        $i.LastWriteTime = get-date               
    }

    $b

我对Powershell非常陌生,但是..我现在已经对其进行了修改以获取当前的日期/时间,但是我假设$a.AddMinutes现在可以删除/修改,因为这不是必需的?$a=获取日期$b=获取子项“C:\MyFiles”foreach($I in$b){$I.LastWriteTime=$a$a=$a.AddMinutes(0)}$bPerfect!。现在修改了所有子文件夹中的时间/日期!。我想您不介意帮我做上述评论,是否需要$a.AddMinutes?因为我不需要将日期显示为其上一个文件的+1分钟,所以可以将所有这些都设置为今天的日期/时间。Cheel!。这比我需要的要远一点,但是,如何将所选目录“C:\MyFiles”更改为实际输入,从而允许我只需输入我需要的目录即可,因为这是我现在唯一需要在脚本(.ps1)本身中手动修改的内容。@welowkey编辑了我的aswer。试试看