gpt4 book ai didi

powershell - 使用 Powershell 移动具有在文本文件中列出的名称的目录

转载 作者:行者123 更新时间:2023-12-03 00:52:19 25 4
gpt4 key购买 nike

这应该很容易,但我正把头撞在 table 上试图弄清楚。

我有一个包含目录名称列表的文本文件。
例如:

Get-Content C:\file.txt
yellow
green
red

我想将 E:\dir1 中的每个目录移动到文件中列出的名称的 E:\dir2 中。
例如:
如果 dir1 有目录“绿色、棕色、黄色、黑色”,我想将“绿色、黄色”移动到 dir2。
Get-Content C:\file.txt | Foreach-Object -Process rename/move "E:\dir1\"$_ "E:\dir2\"$_

以上只是一个猜测,我相信它很遥远。

通常在 Bash 中,我会编写一个类似于以下内容的脚本。
For dir in `cat ./file.txt`
do
mv ~/$dir /old/$dir
echo "moving ~/$dir to /old/$dir"
done

谢谢!

最佳答案

我觉得你很亲近

试试这个:

Get-Content C:\file.txt | 
Foreach-Object {
move-item -path "E:\dir1\$_" -destination "E:\dir2\$_"
}

关于powershell - 使用 Powershell 移动具有在文本文件中列出的名称的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20499433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com