繁体   English   中英

错误或功能? Powershell 7.2.6 移动项目重新案例在 Windows 10 上移动文件

[英]Bug or Feature? Powershell 7.2.6 Move-Item re-cases moved file on Windows 10

在 Windows 10 上的 PowerShell (7.2.6) 中使用 Move-Item cmdlet 时,文件将从其现有大小写“重新大小写”到用于识别它的-Path参数中使用的任何大小写。 由于 windows 在其文件系统中不区分大小写,因此我们希望路径上匹配,但我没想到移动的文件会重新大小写为用于找到它的文件(而不是磁盘上的原始大小写文件)。

这是错误还是功能? 我在文档中找不到任何提及此行为的内容

例如:

<# PowerShell Script to demonstrate how Move-Item changes the casing of a file 
   based on the case used in the Path parameter.
#>

$base_dir = '~'
$original_file_name = 'test.txt'
$original_file_path = [System.IO.Path]::Combine($base_dir, $original_file_name)
$search_filename = $original_file_path.ToUpper()        # deliberaly change the case of the file
$move_to_path = [System.IO.Path]::Combine($base_dir, 'testsubfolder')   # this folder will be removed so ensure it doesn't match something you already have in your home folder that you want to keep
$cleanup = $true    # set to false to persist files used for testing

# Create a file to test
Set-Content -Path $original_file_path -Value "hello world"

# Setup a subfolder to move the file to
if ((Test-Path -Path $move_to_path)) { Remove-Item -Path $move_to_path }
New-Item $move_to_path -ItemType Directory -Force | Out-Null

# Show the casing of the original file
Get-ChildItem -Path ([System.IO.Path]::Combine($base_dir, '*')) -Filter $original_file_name | Select-Object -Property FullName

# Deliberately case the name of the file differently, starting with a capital 'T'
Move-Item -Path $search_filename -Destination $move_to_path | Out-Null

#Show the casing of the 'moved' file
Get-ChildItem -Path $move_to_path | Select-Object -Property FullName

if ($cleanup)
{
    if (Test-Path -Path $original_file_name -PathType Leaf) { Remove-Item -Path $original_file_name }
    if (Test-Path -Path $move_to_Path -PathType Container) { Remove-Item -Path $move_to_path }
}

你会得到 output 的:

FullName
--------
C:\Users\You\test.txt
C:\Users\You\subfolder\TEST.TXT

如您所见,移动文件现在有一个与用于指定原始路径的大小写匹配的大小写,而不是原始文件的大小写。 我原以为顾名思义,应该移动文件,而不是“重新处理”。 Yes, on a Windows system this is functionally the same file as Windows is not case sensitive, but I'd have thought that PowerShell 7.2.6 being cross platform, that this would be unwanted behaviour on Windows.

当打包在基于 linux 的系统上使用的应用程序时,这给我带来了一些小问题,该系统期望不同的文件大小写(由于这种行为,文件被重新大小写)。

这是错误还是功能?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM