【发布时间】:2019-01-29 12:16:54
【问题描述】:
我想要一个 powershell 脚本,它会根据文件的日期将文件移动到文件夹中,然后根据文件名的前 3 个字符移动到子文件夹中。 我已经能够将文件移动到一个过时的文件夹,但不知道如何继续使用 powershell 创建子文件夹并将文件移动到正确的日期子文件夹。这就是我所拥有的并且正在为该日期工作:
Get-ChildItem \\servername\path\path\path\path\New_folder\*.* -Recurse | foreach {
$x = $_.LastWriteTime.ToShortDateString()
$new_folder_name = Get-Date $x -Format yyMMdd
$des_path = "\\servername\path\path\path\path\$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
}
}
【问题讨论】:
标签: powershell