我的电子书都在$home\Documents\books里面.
我有只有一本powershell的电子书, 我输入find-book powershell, 或者 find-book *powershell* 就能直接打开它, 通配符可以加也可以不加
我有好几本java的电子书, 输入find-book java, 会弹出一个图形化的选择框, 按方向键选择, 再按enter就能打开.
find-book.ps1
[cmdletbinding()] param( [Parameter(Mandatory = $true, ValueFromPipeline = $true)] [string]$name ) $fileList = Get-ChildItem -Path "$home\Documents\books" -File -Recurse | Where-Object { if (!($name.Contains( '*'))) { $name = "*$name*" } $ebookExtension='.pdf','.epub','.mobi','.azw3','.maff','.html','.chm','.txt','.doc','.docx','.caj' $_.BaseName -like $name -and $_.Extension -in $ebookExtension } if ($fileList -is [array]) { $selectedFile = @($fileList | Out-GridView -Title 'Choose a file' -PassThru) if ($selectedFile -ne $null) { Invoke-Item $selectedFile.pspath } } elseif ($fileList -ne $null) { Invoke-Item $fileList.pspath } else { write-output "$name not found." }
本文链接: https://www.pstips.net/open-ebook.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!