gpt4 book ai didi

powershell - 在PowerShell代码中测试文件夹是否是连接点?

转载 作者:行者123 更新时间:2023-12-04 00:53:16 24 4
gpt4 key购买 nike

如果文件夹是连接点,如何在PowerShell代码中进行测试?

最佳答案

看一下这个博客:
https://web.archive.org/web/20190422210654/https://devblogs.microsoft.com/powershell/viewing-junctions-with-dir/

做到这一点的方法是复制内置文件系统格式文件,对其进行修改以指示连接,然后使用Update-FormatData加载该文件:

从博客:

The file system formatting rules are in $pshome\FileSystem.Format.ps1xml. I copied this, then in the element [ViewDefinitions –> View –> TableControl –> TableRowEntries –> TableRowEntry –> TableColumnItems –> TableColumnItem] I changed the content of PropertyName with value of 'Mode' to the following:

<ScriptBlock> 
"$($_.Mode)$(if($_.Attributes -band [IO.FileAttributes]::ReparsePoint)
{'J'})" </ScriptBlock>

This does a bitwise AND on the DirectoryInfo object Attributes property ($_.Attributes) against the .Net System.IO.FileAttributes.ReparsePoint enum value. If the result is not zero, it displays a ‘J’ next to the other file mode attributes. Next, load the new formatting file like this:

 PS> Update-FormatData -PrependPath myFilesystem.format.ps1xml

The PrependPath parameter ensures that the new formatting file is loaded before the built-in formatting files.

Directory alink has a ‘J’ in the mode column, seems to work!

It's in the Mode column J for Junction.

关于powershell - 在PowerShell代码中测试文件夹是否是连接点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2311105/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com