从文件快速访问文件资源管理器的新 pin
New pin to quick access in file Explorer from a file
有一个脚本可以创建新的 pin 以从文件在文件资源管理器中快速访问
这是脚本:
#New pin to quick access in file Explorer from a file
$ShortcutsFile = 'H:\_ProfilBackup\Genveje.txt'
$listFile = Get-Content $ShortcutsFile
$o = new-object -com shell.application -Verbose
foreach ($line in Get-Content $ShortcutsFile) {
if ($line -match $regex) {
$o.Namespace($line).Self.InvokeVerb("pintohome")
}
}
谁能解释一下它为什么有效?
我对这条线有点困惑:
foreach ($line in Get-Content $ShortcutsFile) {
if ($line -match $regex)
已尝试其他方式从文件中读取内容。
但是只有当文件中只有一行时它才有效。
如果我使用上面的脚本,我只能让它处理文件中的多行
要读取文件,您要么必须像 post 所示那样循环,要么以原始格式导入。如果您尝试处理许多引脚,则意味着循环。这就是那条线所做的一切。
$regex
只是一个变量,有一些字符串可以用来比较真假,但你没有显示那部分代码。
# Read the shortcuts file, one line at a time, to the end of the file
# If any line read, matches the regex string, do something with that match
foreach ($line in Get-Content $ShortcutsFile) {
if ($line -match $regex)
OP 更新
关于您的 post 和用例,可以对此进行调整。
# What is in the file
Get-Content -Path 'C:\Temp\QuickLinks.txt'
c:\scripts
C:\techtools
c:\temp
$ShellObj = New-Object -ComObject shell.application -Verbose
ForEach ($line in (Get-Content -Path 'C:\Temp\QuickLinks.txt'))
{$ShellObj.Namespace($line).Self.InvokeVerb("pintohome")}
有一个脚本可以创建新的 pin 以从文件在文件资源管理器中快速访问
这是脚本:
#New pin to quick access in file Explorer from a file
$ShortcutsFile = 'H:\_ProfilBackup\Genveje.txt'
$listFile = Get-Content $ShortcutsFile
$o = new-object -com shell.application -Verbose
foreach ($line in Get-Content $ShortcutsFile) {
if ($line -match $regex) {
$o.Namespace($line).Self.InvokeVerb("pintohome")
}
}
谁能解释一下它为什么有效?
我对这条线有点困惑:
foreach ($line in Get-Content $ShortcutsFile) {
if ($line -match $regex)
已尝试其他方式从文件中读取内容。
但是只有当文件中只有一行时它才有效。
如果我使用上面的脚本,我只能让它处理文件中的多行
要读取文件,您要么必须像 post 所示那样循环,要么以原始格式导入。如果您尝试处理许多引脚,则意味着循环。这就是那条线所做的一切。
$regex
只是一个变量,有一些字符串可以用来比较真假,但你没有显示那部分代码。
# Read the shortcuts file, one line at a time, to the end of the file
# If any line read, matches the regex string, do something with that match
foreach ($line in Get-Content $ShortcutsFile) {
if ($line -match $regex)
OP 更新
关于您的 post 和用例,可以对此进行调整。
# What is in the file
Get-Content -Path 'C:\Temp\QuickLinks.txt'
c:\scripts
C:\techtools
c:\temp
$ShellObj = New-Object -ComObject shell.application -Verbose
ForEach ($line in (Get-Content -Path 'C:\Temp\QuickLinks.txt'))
{$ShellObj.Namespace($line).Self.InvokeVerb("pintohome")}