gpt4 book ai didi

powershell - 试图复制包含在文本文件中的一组文件

转载 作者:行者123 更新时间:2023-12-03 16:26:27 24 4
gpt4 key购买 nike

我正在尝试从 txt 文件复制文件列表,作为新手,我遇到了困难。

这是文本文件的一部分。真实文件没有多余的行,但我必须这样做:

"D:\Shared\Customer Care\Customer Care Common\Customers Contracted\Customers Contracted\Fred 44705"
"D:\Shared\Customer Care\Customer Care Common\Customers Contracted\Customers Contracted\Johnson 47227"
"D:\Shared\Customer Care\Customer Care Common\Customers Contracted\Customers Contracted\Daniel 35434"
"D:\Shared\Customer Care\Customer Care Common\Customers Contracted\Customers Contracted\Frank, John 48273"

我也试过用双引号将文件名字符串括起来。

这是我尝试使用的简单脚本:

Get-Content c:\users\scripts\files-to-fix.txt | Foreach-Object {copy-item $_ d:\junk}

我得到的错误是:

Copy-Item : Cannot find drive. A drive with the name ''D' does not exist. At C:\users\mhyman\scripts\copyfiles.ps1:2 char:81 + Get-Content c:\users\mhyman\scripts\files-to-fix.txt | Foreach-Object {copy-item <<<< $_ d:\junk} + CategoryInfo : ObjectNotFound: ('D:String) [Copy-Item], DriveNotFoundException + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.CopyItemCommand


我知道这很简单,但我非常感谢您的帮助。

最佳答案

我认为是周围的引号导致了问题(如错误所示,指出未找到名称为 "D 的驱动器。试试这个:

get-content c:\users\scripts\files-to-fix.txt | %{ copy-item $_.trim('"') d:\junk}

当然,如果你能控制txt文件,输入不带引号的列表

关于powershell - 试图复制包含在文本文件中的一组文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7641580/

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