Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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
Powershell 批处理-根据文件夹创建日期查找和移动文件夹_Powershell_Batch File - Fatal编程技术网

Powershell 批处理-根据文件夹创建日期查找和移动文件夹

Powershell 批处理-根据文件夹创建日期查找和移动文件夹,powershell,batch-file,Powershell,Batch File,我正在尝试创建执行以下操作的批处理(或PowerShell)脚本: 获取当前日期(即2018年6月21日) 查看特定文件夹中的所有子文件夹(不是递归的,只是即时子文件夹),并查找上一年创建日期为上一年当前日期(即2017年1月1日-2017年6月21日)的所有文件夹 将所有这些文件夹移动到“2017作业”文件夹 所以我一直在寻找这个问题的答案,但一切似乎都围绕着文件日期,而不是文件夹日期,所以我们来了。我知道如何使用Robocopy在找到文件夹后移动文件夹,但它的所有开关都基于移动早于X日期的文

我正在尝试创建执行以下操作的批处理(或PowerShell)脚本:

  • 获取当前日期(即2018年6月21日)
  • 查看特定文件夹中的所有子文件夹(不是递归的,只是即时子文件夹),并查找上一年创建日期为上一年当前日期(即2017年1月1日-2017年6月21日)的所有文件夹
  • 将所有这些文件夹移动到“2017作业”文件夹

  • 所以我一直在寻找这个问题的答案,但一切似乎都围绕着文件日期,而不是文件夹日期,所以我们来了。我知道如何使用Robocopy在找到文件夹后移动文件夹,但它的所有开关都基于移动早于X日期的文件,而不是文件夹。关于如何实现基于文件夹的创建日期循环查找,有什么想法吗

    在不为您构建整个脚本的情况下,以下是您的作品:

    $date = Get-Date
    $dateAYearAgo = $date.AddYears(-1)
    
    $items = Get-ChildItem "C:\base\folder" | Where-Object {$_.CreationTime -gt $start -and $_.CreationTime -lt $end}
    $items | Move-Item "C:\base\folder\2017 Jobs"
    

    至于只筛选文件夹,您可以查看您所在的powershell版本是否允许
    Get ChildItem C:\-目录
    仅提取目录,或者您可以使用
    Get ChildItem C:\\\\124; Where Object{$\u.PSIsContainer}

    而不为您构建整个脚本,以下是您的作品:

    $date = Get-Date
    $dateAYearAgo = $date.AddYears(-1)
    
    $items = Get-ChildItem "C:\base\folder" | Where-Object {$_.CreationTime -gt $start -and $_.CreationTime -lt $end}
    $items | Move-Item "C:\base\folder\2017 Jobs"
    
    至于只筛选文件夹,您可以查看您所在的powershell版本是否允许
    Get ChildItem C:\-目录
    仅提取目录,或者您可以使用
    Get ChildItem C:\\\124; Where Object{$\uu0.PSIsContainer}

    可能重复的