我在移动包含空格的文件时遇到了问题。
This is the example path: $transfer.FileName = D:\this\is\a\file with a lot of spaces.xml
$file = $transfer.FileName
Move-Item -path $file -Destination $archiveFolder
错误:
Move-Item : Illegal characters in path.
At line:1 char:17
+ Move-Item -path $file -Destination $archiveFolder
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (D:\this\i...ong 2022-08.xml:FileInfo) [Move-Item], ArgumentException
+ FullyQualifiedErrorId : MoveFileInfoItemArgumentError,Microsoft.PowerShell.Commands.MoveItemCommand
当我运行test-path $file
时,我会接收$true
。我试着用"`“替换空格,但是在那之后,我收到了一个新的错误,说路径不正确。
有人知道我怎么解决这个问题吗?
发布于 2022-09-02 14:45:00
我无法复制你的问题。
$filename = "D:\Desktop\New folder\New Text Document.txt"
$archiveFolder = "D:\Desktop\New folder\temp"
Move-Item -path $filename -Destination $archiveFolder
没有返回错误,文件被移动。你是否在文件名中加上双引号?
https://stackoverflow.com/questions/73584224
复制相似问题