在注册表和gpedit.msc中启用长文件路径不起作用 [英] Enabling long file path in registry and gpedit.msc is not working
问题描述
我需要使用powershell cmd创建文件路径大于250个字符的长文件夹.
I need to create folder with long file path more than 250 char using powershell cmd.
我做了以下事情,
1,在此注册表路径"HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ FileSystem"中,我已将LongPathsEnabled的值更改为"1"
1, In this registry path "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem", I had changed the value for LongPathsEnabled as '1'
2,我已在本地计算机策略>计算机配置>管理模板>系统>文件系统>启用Win32长路径"(gpedit.msc)中启用了长文件路径
2,I have enabled long file path in "Local Computer Policy > Computer Configuration > Administrative Templates > System > Filesystem >Enable Win32 long paths" (gpedit.msc)
但是当使用power shell cmd创建一个包含250个以上字符的文件夹时,它会抛出如下错误
But while creating a folder with more than 250 char using power shell cmd , its throwing a error as below
"New-Item:指定的路径,文件名或两者都太长.完全限定的文件名必须小于260字符,并且目录名称必须少于248个字符."
"New-Item : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters."
推荐答案
应用 \\?\
前缀,如以下示例所示:
Apply the \\?\
prefix as in the following example:
$longPart = $( 65..86 | ForEach-Object {
[string][char]$_ * 10
} ) -join '\'
$Path = "\\?\D:\PShell\DataFiles\$longPart"
$longPart.Length, $Path.Length -join ','
New-Item -ItemType Directory -Path $Path
241,265
Directory: \\?\D:\PShell\DataFiles\AAAAAAAAAA\BBBBBBBBBB\CCCCCCCCCC\DDDDDDD
DDD\EEEEEEEEEE\FFFFFFFFFF\GGGGGGGGGG\HHHHHHHHHH\IIIIIIIIII\JJJJJJJJJJ\KKKKK
KKKKK\LLLLLLLLLL\MMMMMMMMMM\NNNNNNNNNN\OOOOOOOOOO\PPPPPPPPPP\QQQQQQQQQQ\RRR
RRRRRRR\SSSSSSSSSS\TTTTTTTTTT\UUUUUUUUUU
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 03.01.2020 22:58 VVVVVVVVVV
对于文件I/O,路径字符串的前缀"
\\ ??
"告诉WindowsAPI禁用所有字符串解析并发送随后的字符串直接进入文件系统.
For file I/O, the "
\\?\
" prefix to a path string tells the Windows APIs to disable all string parsing and to send the string that follows it straight to the file system.
...
由于它关闭了路径字符串的自动扩展,因此" \\?\
"前缀还允许在路径中使用" ..
"和".
"名称,如果您尝试执行操作,可能会很有用在具有这些否则保留的相对路径说明符的文件上完全合格路径的一部分.
Because it turns off automatic expansion of the path string, the
"\\?\
" prefix also allows the use of "..
" and ".
" in the path
names, which can be useful if you are attempting to perform operations
on a file with these otherwise reserved relative path specifiers as
part of the fully qualified path.
请注意,不能将" \\ ??
"前缀与相对路径一起使用.
Note that you cannot use the "\\?\
" prefix with a relative path.
在注册表中使用以下 LongPathsEnabled
:
reg.exe query "HKLM\SYSTEM\CurrentControlSet\Control\FileSystem" -v long*
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
LongPathsEnabled REG_SZ 1
这篇关于在注册表和gpedit.msc中启用长文件路径不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!