- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
因此,我阅读了很多有关使用 Powershell 重命名文件的方括号 [] 问题。这些帖子中的大多数都谈到了删除括号。我需要保留括号,只删除文件扩展名 .crypted(CryptoLocker)
。有 400,000 多个文件和 172,000 多个文件夹。我尝试了 Move-Item cmdlet...
Get-ChildItem c:\temp *.crypted | Move-Item -LiteralPath {$_.FullName.Replace(".crypted", "")}
我得到一个错误 Move-Item : Cannot move item because the item at 'C:\temp\Rule [1].txt' does not exist
您可能会看到新路径是正确的,但它说它不存在。我很难过。任何帮助将不胜感激。
最佳答案
调试提示:当您遇到代码问题并且正在使用管道时,请重写代码以不使用管道并将问题分解为多个步骤并插入调试辅助工具以帮助解决问题。可以是 Write-Host,保存到临时变量等。
对我来说,你写的 Move-Item 不起作用,我收到了类似的错误消息。
这是我得出的解决方案:
Get-ChildItem *.crypted | ForEach-Object {Move-Item -LiteralPath $_.FullName $_.FullName.Replace('.crypted', '')}
请注意,我在 -LiteralPath
之后将 2 个参数传递给 Move-Item
,并且不需要反引号或任何不寻常的东西。
这是我演示问题的工作,以及我的解决方案。
D:\test\move> dir
Directory: D:\test\move
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 3/17/2016 9:21 PM 100347 file [1].pdf
D:\test\move> Get-ChildItem *.pdf | Move-Item -LiteralPath {$_.FullName.Replace('1', '2')}
Move-Item : Cannot move item because the item at 'D:\test\move\file [2].pdf' does not exist.
At line:1 char:23
+ ... ldItem *.pdf | Move-Item -LiteralPath {$_.FullName.Replace('1', '2')}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Move-Item], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.MoveItemCommand
D:\test\move> Get-ChildItem *.pdf | ForEach-Object {Move-Item -LiteralPath $_.FullName $_.FullName.Replace('1', '2')}
D:\test\move> dir
Directory: D:\test\move
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 3/17/2016 9:21 PM 100347 file [2].pdf
也适用于扩展...
D:\test\move> dir
Directory: D:\test\move
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 3/17/2016 9:21 PM 100347 file [2].txt.crypted
D:\test\move> Get-ChildItem *.crypted | ForEach-Object {Move-Item -LiteralPath $_.FullName $_.FullName.Replace('.crypted', '')}
D:\test\move> dir
Directory: D:\test\move
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 3/17/2016 9:21 PM 100347 file [2].txt
D:\test\move>
关于带方括号的 PowerShell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36077232/
我一直想知道两者之间有什么区别 mov esi,eax 和 mov [esi],eax 曾经是。 感谢任何帮助。 最佳答案 mov esi,eax 将寄存器eax的内容写入寄存器esi。 mov [e
如果有人能帮助我满足 JAVA 正则表达式要求,我将不胜感激我有一个像 "/ABC/KLM[XYZ/ABC/KLM]/ABC"这样的字符串 我想替换所有不用方括号括起来的ABC。在这种情况下,只应找到
我需要替换 key:value 对周围的方括号,类似于以下内容。任何帮助深表感谢! “属性”中的数据如下所示: name: property1 value: [12345667:97764458] *
我正在尝试使用某种 grok 模式来使用以下日志记录格式: *Sun 07:05:18.372 INFO [main] [userID] perf - 0ms - select x from y 我
我在 R 中有一个函数,看起来有点像这样: setMethod('[', signature(x="stack"),definition=function(x,i,j,drop){ new('cl
我将这些定义放在一个文件中: x = 'a' : 'b' : 'c' : [] y = ['a', 'b', 'c'] (重要的是在文件中定义它们,而不是在 GHCi 中,因为在后一种情况下,事情变得
我喜欢将DocBlockr插件用于精美文字,但我希望自己的评论有所不同。 正常出现: 以及我希望它们出现的方式: 因此,是否有这样做的type,description和[]方括号呢?我已经搜寻了一下,
让我们考虑以下是我的对象: var n = {"aa":"x","dd":'d'}; 我在 Object.assign 中使用方括号.它给出了以下结果。 [aa: "x", dd: "d"] .最终代
我正在尝试使用正则表达式从 KEY PAIR VALUE 中找出 VALUE。 VALUE 可以有 [ ](方括号)。如果 VALUE 中存在 [ ](方括号),那么我只想提取 [ ] 之外的字符。
这个问题在这里已经有了答案: What is array literal notation in javascript and when should you use it? (4 个答案) 关闭
这个问题在这里已经有了答案: What do square brackets around a property name in an object literal mean? (2 个答案) 关闭
我有一个语法标记指定为: list_value = Suppress(oneOf("[ (")) + Group( delimitedList(string_value | int_value
如何替换这种格式的标记: [a href="/my_page" style="font-size: 13px"]click me[/a] 到 click me 使用 preg_replace()? 我
使用下面的代码,我可以将 Number123(45) 转换为 Number。 $string = 'Number123(45)'; $string2 = preg_replace('/[0-9]+
我知道硬括号('[' 和 ']')用于标识数组,但是在搜索如何使用事件时,我偶然发现了它们的另一种用法,并且想知道它到底意味着什么...... 我看到的代码 ( link ) 如下所示: // evh
This question already has an answer here: gRPC/Protobuf 3 syntax: what is the difference between rpc
在vim中,您可以通过vi“,vi [,vi(... 例如,如果您有这样的一行: x = "difference between vim and emacs" 并且光标位于这些引号之间的任意位置,然后
AngularJS将方括号用作其指令的参数 (input[number]) 但是Jade also uses square brackets for class attributes。 所以这行不通
正则表达式中的点. 匹配任何单个字符。为了使正则表达式匹配点,必须对点进行转义:\. It has been pointed out to me方括号 [] 内的点不必转义。例如,表达式:[.]{3}
这个问题已经有答案了: What is the difference between square brackets and parentheses in a regex? (3 个回答) 已关闭 8
我是一名优秀的程序员,十分优秀!