如何在Powershell的目录中生成.htm文件的超链接? [英] How to generate hyperlinks to .htm files in a directory in Powershell?

查看:94
本文介绍了如何在Powershell的目录中生成.htm文件的超链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想扫描.htm文件的目录,然后生成那些.htm文件的超链接,并将结果输出到新的HTML文档。实现这一目标的最佳方法是什么?

I would like to scan a directory for .htm files and then generate hyperlinks to those .htm files and output the result to a new HTML document. What is the best way to achieve this?

到目前为止我有这个:

Get-ChildItem "C:\test1\*.htm" -Recurse -Force |
  ConvertTo-Html -Fragment FullName, Name `
    -PreContent '<html><head><title>Test</title></head><body>' `
    -PostContent '</body></html>' |
  % { $_ -replace '<th>.*</th>','<th>Files</th>' `
         -replace '<td>(.*?)</td><td>(.*?)</td><td>(.*?)</td>',
                  '<td><a href="$1">$2</a> $3</td>'

  } | Set-Content "C:\$env:COMPUTERNAME-$(Get-Date -f dd-MM-yyyy-hh-mm-ss).htm"


推荐答案

您可以尝试这样的事情:

You could try something like this:

Get-ChildItem "C:\*.htm" -Recurse -Force |
  ConvertTo-Html -Fragment FullName, Name, LastWriteTime `
    -PreContent '<html><head><title>Test</title></head><body>' `
    -PostContent '</body></html>' |
  % { $_ -replace '<th>.*</th>','<th>Files</th>' `
         -replace '<td>(.*?)</td><td>(.*?)</td><td>(.*?)</td>',
                  '<td><a href="$1">$2</a> $3</td>'

  } | Set-Content "C:\$env:COMPUTERNAME-$(Get-Date -f dd-MM-yyyy).htm"

这篇关于如何在Powershell的目录中生成.htm文件的超链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆