返回列表 发帖

[已解决]dos如何在同级及子集所有txt文件的第一行后插入一行内容?

本帖最后由 O.0 于 2019-5-18 19:44 编辑

例:
源文件:
111
222
333
修改后:
111
444
222
333

@echo off
set info=互助互利,支付宝扫码头像,感谢赞助
rem 有问题,可加QQ956535081及时沟通
title %info%
cd /d "%~dp0"
powershell -NoProfile -ExecutionPolicy bypass ^
    $n=1;^
    $str='444';^
    dir -r^|?{($_ -is [System.IO.FileInfo]) -and ($_.Extension -eq '.txt')}^|%%{^
        write-host $_.FullName;^
        $text=[IO.File]::ReadAllLines($_.FullName,[Text.Encoding]::Default);^
        if($text.Count -ge $n){^
            $text[$n-1]+=(\"`r`n\"+$str);^
            [IO.File]::WriteAllLines($_.FullName, $text, [Text.Encoding]::Default);^
        };^
    };^
    write-host '%info%' -ForegroundColor green;
pauseCOPY
1

评分人数

    • O.0: 谢谢技术 + 1
提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

本帖最后由 amwfjhh 于 2019-5-18 15:24 编辑
@echo off
set /p "strInsert=Please input the insert content:"
for /f "tokens=*" %%i in ('dir /s/b/a-d *.txt') do (
call :_Insert %%~si
)
pause
goto :EOF
:_Insert
(
set /p=<nul>$.tmp
echo,Current file : %1
for /f "tokens=1,* delims=:" %%a in ('findstr /n .* %1') do (
echo,%%b>>$.tmp
if "%%a" equ "1" (
echo,%strInsert%>>$.tmp
)
)
type $.tmp
move /y $.tmp %1
echo,&echo,
goto :EOF
)COPY
echo,hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5x>in.com

TOP

感谢两位大佬,已解决。

TOP

不好意思,新人帖子发错版块了。

TOP

回复 5# O.0


    无妨。小问题。
echo,hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5x>in.com

TOP

嗯,要用心,注意提示
提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

返回列表