html - How to modify Powershell code so that hyperlinks are only created for the files but not the directories? -
i'm using code below generate index.htm page. code works great, thing don't want inside index.htm page have hyperlinks directories, useless. index.htm should contain hyperlinks .htm files inside c:\inetpub\wwwroot. suggestions on how achieve such result?
$basedir = 'c:\inetpub\wwwroot' $exp = [regex]::escape($basedir) $server = 'http://172.16.x.x' get-childitem $basedir -force | select name, lastwritetime, @{n="url";e={$_.fullname -replace $exp, $server -replace '\\', '/'}} | convertto-html -fragment url, 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:\inetpub\wwwroot\index.htm"
you can filter out folder in way:
get-childitem $basedir -force | ? { -not $_.psiscontainer } | ... rest of code ...
in powershell v3
get-childitem $basedir -force -file | ... rest of code ...
Comments
Post a Comment