本帖最后由 flashercs 于 2022-7-31 18:19 编辑
- <#*,:&cls
- @echo off
- cd /d "%~dp0"
- powershell -C "Set-Location -LiteralPath ([Environment]::CurrentDirectory);. ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~f0\" -ReadCount 0 | Out-String)))"
- pause
- exit /b
- #>
- $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 {}
- }
复制代码
|