$PSVersionTable
[Environment]::NewLine
$inPath="C:\Users\foo\Documents\memo"
$outPath="C:\Users\foo\Documents\memo_md"
function myFilter($inText) {
$outText=""
for ( $i = 0; $i -lt $inText.Length; $i++ ) {
$line = ([string]$inText[$i]) -creplace "^=== *","### "
$line = $line -creplace "^== *","## "
$line = $line -creplace "^= *","# "
if($i -eq 0) {
$outText = $line
} else {
$outText = $outText + "`r`n" + $line
}
}
return $outText
}
$count=0
$files = get-childitem $inPath -include *.txt -recurse
foreach($file in $files) {
if($count -gt 10) {
#return
}
# $file.fullname
$content = (Get-Content $file)
if($content) {
# ファイルに出力する
Add-content -Path ($outPath+"\"+($file.basename)+".md") -Value (myFilter $content).toString() -Encoding UTF8
}
$count=$count+1
}
Win32APIにあるSystemParametersInfo関数を呼び出す必要がある。
v2以降はAdd-Typeで行ける。
[console]::TreatControlCAsInput = $true
if ([console]::KeyAvailable) {
$key = [system.console]::readkey($true)
if (($key.modifiers -band [consolemodifiers]"control") -and($key.key -eq "C")) {
"Terminating..."
break
}
}
powershell.exe -noexit c:\work\hoge.ps1
$a = get-childitem c:\foo\bar
foreach( $b in $a ) {
$b.name
}
$a = get-childitem c:\foo\bar\* -include *.txt
gc hoge.txt
v3から追加された。
改行も取り込む。このオプションがないと行単位で読み込まれたオブジェクトなる。
select-string
"hogafuga<starttag aabas><a></a><b>" -match '(<starttag .*)'
Get-Content -Encoding UTF8 fuga.txt
$xmlDoc = [xml]"<root><child1>1</child1><child2>2</child2></root>"
$navi = [Xml.Xpath.XPathNavigator] $xmlDoc.CreateNavigator()
$navi.MoveToFirstChild()
$nodes = $navi.Select("/tag1/tag2[@param=val]",$nsmgr)
While ( $nodes.MoveNext() ){
$nodes.Current.Value
$nodes.Current.SetValue("hoo")
}
- 真面目に実装する
- libuvのDLLを叩けばよい?
- 動的にExeのイメージをDLして実行してしまうw
$Args[0]