本帖最后由 pcl_test 于 2015-4-19 23:17 编辑
- @echo off
- setlocal enabledelayedexpansion
- set "folder=处理结果"
- md "%folder%\" 2>nul
-
- for /f "delims=" %%a in ('dir /b *.csv') do (
- set t=0
- md "%%~na_tmp\" 2>nul
-
- for /f "usebackq delims=" %%b in ("%%a") do (
- set "str=%%b"
- if "!str:~,2!" equ "距离" (
- set/a t+=1
- ) else (
- >>"%%~na_tmp\%%~na_!t!.txt" echo,%%b
- )
- )
-
- pushd "%%~na_tmp\"
- (for /f "delims=" %%c in ('dir /b *.txt') do (
- ::取里程值
- for /f "tokens=1,2 delims=," %%d in ('type "%%c" ^|findstr ",,"') do set "a=%%d"
-
- ::取0距离的高程值
- for /f "usebackq tokens=1,2 delims=," %%e in ("%%c") do if "%%e" equ "0" (set "b=%%f")
- echo,!a!,!b!
- if "!b:~-3,1!" equ "." (set "b=!b!0")
- set "b=!b:.=!"
-
- ::处理负距离数据
- set sa=
- set n=0
- for /f "tokens=1,2 delims=," %%g in ('type "%%c" ^|sort /+20 ^|findstr "\-"') do (
- set "fjl=%%g"
- set /a n+=1
- set "c=%%h"
- if "!c:~-3,1!" equ "." (set c=!c!0)
- set "c=!c:.=!"
- set /a d=b-c
- if "!d:-=!" equ "!d!" (
- if "!d:~3,1!" equ "" (
- set "d=00000!d!"
- set "d=!d:~-4!
- )
- set "d=!d:~,-3!.!d:~-3!"
- ) else (
- set "d=!d:-=!"
- if "!d:~3,1!" equ "" (
- set "d=00000!d!"
- set "d=!d:~-4!
- )
- set "d=-!d:~,-3!.!d:~-3!"
- )
- set "sa=!sa!!fjl:~1!,!d!,"
- )
- echo,!n!,!sa!
-
- ::处理正距离数据
- set sb=
- set m=0
- for /f "skip=2 tokens=1,2 delims=," %%i in ('type "%%c" ^|findstr /v "\-"') do (
- set /a m+=1
- set "e=%%j"
- if "!e:~-3,1!" equ "." (set e=!e!0)
- set "e=!e:.=!"
- set /a f=b-e
-
- if "!f:-=!" equ "!f!" (
- if "!f:~3,1!" equ "" (
- set "f=00000!f!"
- set "f=!f:~-4!
- )
- set "f=!f:~,-3!.!f:~-3!"
- ) else (
- set "f=!f:-=!"
- if "!f:~3,1!" equ "" (
- set "f=00000!f!"
- set "f=!f:~-4!
- )
- set "f=-!f:~,-3!.!f:~-3!"
- )
- set "sb=!sb!%%i,!f!,"
- )
- echo,!m!,!sb!
-
- ))>"%~dp0%folder%\%%~na.csv"
-
- popd
- rd "%%~na_tmp\" /s /q
- )
-
- pause
复制代码
|