尝试复制文本文件中包含的一组文件
我正在尝试从 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}
我收到的错误是:
复制项目:找不到驱动器。名称为“D”的驱动器不 存在。在 C:\users\mhyman\scripts\copyfiles.ps1:2 字符:81 + 获取内容 c:\users\mhyman\scripts\files-to-fix.txt | Foreach-Object {复制项 <<<<< $_ d:\垃圾} + CategoryInfo : ObjectNotFound: ('D:String) [复制项目], 驱动器未发现异常 +完全限定错误ID: DriveNotFound,Microsoft.PowerShell.Commands.CopyItemCommand
我知道这很简单,但我真的很感激一些帮助。
I'm trying to copy a list of files from a txt file and as a newbie, I'm having a hard time.
Here is a bit of the text file. The real file has no extra lines, but I had to do that to :
"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"
I've tried enclosing the filename string in double-quotes as well.
Here's the simple script I'm trying to use:
Get-Content c:\users\scripts\files-to-fix.txt | Foreach-Object {copy-item $_ d:\junk}
The error I'm getting is:
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
I know this is simple, but I would really appreciate some help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为是周围的引号引起了问题(如错误所示,未找到名为
"D
的驱动器。尝试一下:当然,如果您可以控制 txt 文件,输入不带引号的列表。
I think it is the surrounding quotes that are causing the problem ( as indicated by the error saying that a drive of name
"D
is not found. Try this:Of course, if you can control the txt file, enter the list without the quotes.
从你的标签、驱动器号和反斜杠来看,它显然是你工作的 Windows 环境,虽然我不是 PowerShell 脚本编写者,但我比大多数批处理脚本更好,并且使用 For / If 条件语句,因为它更短,你将文件提供给它,而不是将文件解析为一行中的 reduudc 命令,因此在您的示例中:
然后您回家,直到第二天早上才担心
powershell 是否具有 runas 装饰模式,可以解析较旧的、更经过验证且稳定的 DOS 命令?
By your tags and drive letters and backslashes it is clearly a Windows environment your working in and although I'm not a PowerShell scripter, I'm a better than most batch scipter and use a For / If conditioanla statement sicne it is shorter and you feed it your file instead of parsing out the file into reduudc commands on a line, so in your example:
And then you go home and never worry about until the next morning
Does powershell have a runas ornative mode that can parse older, more proven and stable DOS commands ?