本帖最后由 ivor 于 2012-2-5 17:32 编辑
删除所有*.txt 第一行- @echo off & setlocal enabledelayedexpansion
- for /f "delims=" %%a in ('dir /s /b *.txt') do (
- set indicator=nul
- for /f "useback delims=" %%b in ("%%a") do (
- echo %%b
- set indicator=%%a~
-
- )>>"!indicator!"
- move "%%a~" "%%a"
- )
- pause
复制代码 再附上多功能版,列数如果大于4请修改:delCols代码块
功能1.指定删除的行数 2.指定删除的列数 3.同时指定行数和列数- @echo off & setlocal enabledelayedexpansion
-
- set /p rows=请输入要删除的行:
- set /p cols=请输入要删除的列:
-
- if defined rows call :delRows %rows% & pause
- if defined cols call :delCols %cols% & pause
-
- goto :eof
- :delRows
-
- for /f "delims=" %%a in ('dir /s /b *.txt') do (
- set count = %1
- for /f "useback delims=" %%b in ("%%a") do (
- set /a count += 1
- if !count! neq %1 echo %%b >>"%%a~"
- )
- move "%%a~" "%%a"
- )
- echo 已经处理完了行数
- goto :eof
-
- :delCols
- for /f "delims=" %%a in ('dir /s /b *.txt') do (
- for /f "useback tokens=1-4" %%b in ("%%a") do (
- set 1=%%b
- set 2=%%c
- set 3=%%d
- set 4=%%e
- set "%1="
- echo !1! !2! !3! !4! >>"%%a~"
-
-
- )
- move "%%a~" "%%a"
- )
- echo 已经处理完了列数
- goto :eof
复制代码
|