批量拆分多个 CSV 文件

Split multiple CSV files in batch

我已经使用了在 SO 上找到的这个脚本:

Batch file to split .csv file

@echo off
setLocal EnableDelayedExpansion

set limit=50
set file=export.csv
set lineCounter=1
set filenameCounter=1

set name=
set extension=
for %%a in (%file%) do (
    set "name=%%~na"
    set "extension=%%~xa"
)

for /f "tokens=*" %%a in (%file%) do (
    set splitFile=!name!-part!filenameCounter!!extension!
    if !lineCounter! gtr !limit! (
        set /a filenameCounter=!filenameCounter! + 1
        set lineCounter=1
        echo Created !splitFile!.
    )
    echo %%a>> !splitFile!

    set /a lineCounter=!lineCounter! + 1
)

这会将一个文件拆分成几个较小的文件(每个 50 行)。我想让它拆分 specific/current 目录中的所有文件。

最终代码感谢@DavidPostill

@echo off
setLocal EnableDelayedExpansion
for /f "tokens=*" %%f in ('dir /b *.csv') do (

    set limit=100 
    set lineCounter=1
    set filenameCounter=1

    set name=
    set extension=
    for %%a in (%%f) do (
        set "name=%%~na"
        set "extension=%%~xa"
    )

    for /f "tokens=*" %%a in (%%f) do (
        set splitFile=!name!-part!filenameCounter!!extension!"
        if !lineCounter! gtr !limit! (
            set /a filenameCounter=!filenameCounter! + 1
            set lineCounter=1
            echo Created !splitFile!.
        )
        echo %%a>> !splitFile!

        set /a lineCounter=!lineCounter! + 1
    )
)