我有一个文件夹,其中包含子文件夹,每个子文件夹都有许多 excel 电子表格。我试图让powershell搜索子目录,然后将所有具有相同创建日期的xls文件移动到该创建日期的新文件夹中。我很接近我认为这是我的代码。发生的事情是它只查看“报告”中的文件,而不是“报告”的子文件夹。
Get-ChildItem "c:\users\username\documents\reporting\*.xls" -Recurse | foreach {
$x = $_.LastWriteTime.ToShortDateString()
$new_folder_name = Get-Date $x -Format yyyy.MM.dd
$des_path = "c:\users\username\documents\$new_folder_name"
if (test-path $des_path){
move-item $_.fullname $des_path
} else {
new-item -ItemType directory -Path $des_path
move-item $_.fullname $des_path
}
}