替换脚本test2

$path = "你的项目路径"  # 修改为你的实际项目路径

Get-ChildItem -Path $path -Recurse -Filter *.java | ForEach-Object {
    $lines = Get-Content $_.FullName -Encoding UTF8  # 明确读取 UTF-8 编码
    $output = @()  # 用于存储修改后的文件内容
    $modified = $false  # 标记是否有修改

    foreach ($line in $lines) {
        # 替换 int getPersonno 为 long getPersonno
        if ($line -match "int\s+getPersonno") {
            $output += $line -replace "int\s+getPersonno", "long getPersonno"
            $modified = $true
            continue
        }

        # 替换 int personno 为 long personno
        if ($line -match "int\s+personno") {
            $output += $line -replace "int\s+personno", "long personno"
            $modified = $true
            continue
        }

        # 未匹配的行原样保留
        $output += $line
    }

    # 如果内容有修改,写回文件
    if ($modified) {
        [System.IO.File]::WriteAllLines($_.FullName, $output, [System.Text.Encoding]::UTF8)
        Write-Host "文件已更新: $($_.FullName)"
    } else {
        Write-Host "文件未修改: $($_.FullName)"
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值