本帖最后由 flashercs 于 2022-7-31 18:19 编辑
| | | | | | | | | | | | | | | $txtpath = "c:\txt\a.txt" | | $dirdata = "c:\news\1001" | | $dicDataPath = @{} | | $rootdir = [System.IO.Directory]::CreateDirectory($dirdata) | | foreach ($line in (Get-Content -LiteralPath $txtpath -ReadCount 0)) { | | if ($line -match '^\s*$') { | | continue | | } | | $a, $b, $c, $d = $line -split '\|' | | $datapath = [System.IO.Path]::Combine($rootdir.FullName, "${a}_${b}.dat") | | if (-not $dicDataPath.ContainsKey($datapath)) { | | $dicDataPath[$datapath] = 1 | | $filemode = [System.IO.FileMode]::Create | | } else { | | $filemode = [System.IO.FileMode]::Append | | } | | try { | | $stream = New-Object System.IO.FileStream -ArgumentList @($datapath, $filemode, [System.IO.FileAccess]::Write, [System.IO.FileShare]::Read) | | $bw = New-Object System.IO.BinaryWriter -ArgumentList $stream | | $bw.Write($c -as [int]) | | $bw.Write($d -as [float]) | | } finally { | | if ($bw) { | | $bw.Close() | | $bw = $null | | } | | if ($stream) { | | $stream.Close() | | $stream = $null | | } | | } | | trap {} | | }COPY |
|