powershell - PowerShell - 复制文件 X 次并更改其名称
问题描述
你能帮忙告诉PowerShell中是否有单个/尽可能短的命令可以复制文件给定的次数吗?
例如:
file.pdf to file1.pdf, file2.pdf, file3.pdf
在同一个文件夹中。
解决方案
有几种方法可以做到这一点,这是一种使用foreach-object
循环的非常简单的方法。请注意,这仅在您与pdf
文件位于同一位置时才有效。
如果您有疑问,请使用文件的完整路径。
PS /~> $null > 'test.pdf'
PS /~> ls
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 4/8/2021 5:11 PM 2 test.pdf
PS /~> 0..10|%{Copy-Item .\test.pdf -Destination ".\test$_.pdf"}
PS /~> ls
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 4/8/2021 5:11 PM 2 test.pdf
-a---- 4/8/2021 5:11 PM 2 test0.pdf
-a---- 4/8/2021 5:11 PM 2 test1.pdf
-a---- 4/8/2021 5:11 PM 2 test10.pdf
-a---- 4/8/2021 5:11 PM 2 test2.pdf
-a---- 4/8/2021 5:11 PM 2 test3.pdf
-a---- 4/8/2021 5:11 PM 2 test4.pdf
-a---- 4/8/2021 5:11 PM 2 test5.pdf
-a---- 4/8/2021 5:11 PM 2 test6.pdf
-a---- 4/8/2021 5:11 PM 2 test7.pdf
-a---- 4/8/2021 5:11 PM 2 test8.pdf
-a---- 4/8/2021 5:11 PM 2 test9.pdf
推荐阅读
- amazon-web-services - 如何从本地计算机执行 AWS 签名版本 4?
- javascript - 为什么我的 JS 函数不会在 onresize 事件上触发?
- c - 如果我继续重新声明它,为什么 size_t 不抱怨?
- python - ImportError:无法从“oauth2client.service_account”导入名称“ServiceAccountCredentials”
- haskell - 如何在 Haskell 中获取给定数字之前/之后的浮点数?
- python - numpy 的一维高级索引语法的正则表达式 - 如何处理可选的尾随逗号
- c# - VS2019 - ViewBag 在当前上下文中不存在
- .net-core - 查找生成器“身份”...给定的程序集名称或代码库无效
- java - 为什么 android studio 在发布时不生产启动器?
- android - listView为空时如何禁用按钮?