【发布时间】:2016-01-15 16:05:52
【问题描述】:
我想将DateTime 格式的文件夹复制到名为Weekday 的文件夹中。文件夹 D:\TEST\2015-06-23T2300+0000 应复制到 D:\TEST\Thursday。
Get-ChildItem $Path | Select FullName
D:\TEST\2015-06-23T2300+0000
D:\TEST\2016-01-07T2300+0000
Get-ChildItem $Path | ForEach {$_.LastWriteTime.DayOfWeek}
Thursday
Friday
这是我现在有的代码,但它不起作用。我错过了一些东西。
$Path = "D:\TEST"
$source = Get-ChildItem $Path | Select FullName
$dest = Get-ChildItem $Path | ForEach {$_.LastWriteTime.DayOfWeek}
foreach ($source in $sources)
{
Copy-Item -Path $source -Destination "D:\TEST2\$dest" -Recurse
}
欢迎任何帮助。
【问题讨论】:
-
“不工作”是什么意思?究竟会发生什么?你有任何错误吗?
-
在您的示例中,
$dest成为一个字符串数组,其中包含 all 您所有文件的可能工作日 -Copy-Item -Destination无法“猜测”哪个属于每个文件文件 -
什么都没有发生,只需要脚本。没有输出,也没有复制文件。
标签: powershell dayofweek get-childitem copy-item