只保留以下列且按照顺序输出:’Name’,’Email’,’Financial Status’,’Created at’,’Shipping Country’,’Payment Method’,’Payment Reference’,’Vendor’,’Id’,’Payment ID’,’Payment References’
@echo off setlocal EnableDelayedExpansion REM 设置源目录为 bat 文件所在目录 set "sourceDir=%~dp0" REM 去掉末尾的反斜杠 set "sourceDir=%sourceDir:~0,-1%" REM 设置输出目录 set "outputDir=%sourceDir%\output" REM 如果 output 文件夹不存在,则创建 if not exist "!outputDir!" mkdir "!outputDir!" REM 调用 PowerShell 执行 CSV 处理,并添加文件名列 powershell -Command "& { [Console]::OutputEncoding = [System.Text.Encoding]::UTF8; $sourceDir = '%sourceDir%'; $outputDir = '%outputDir%'; if (!(Test-Path -Path $outputDir)) { New-Item -ItemType Directory -Path $outputDir -Force }; $csvFiles = Get-ChildItem -Path $sourceDir -Filter '*.csv'; foreach ($file in $csvFiles) { $outputFile = \"$outputDir\$($file.BaseName)_filtered.csv\"; $fileName = $file.Name; Import-Csv -Path $file.FullName -Encoding UTF8 | Select-Object -Property 'Name','Email','Financial Status','Created at','Shipping Country','Payment Method','Payment Reference','Vendor','Id','Payment ID','Payment References',@{Name='FileName';Expression={$fileName}} | Export-Csv -Path $outputFile -NoTypeInformation -Encoding UTF8 } }" echo 处理完成,结果已保存到 !outputDir! pause
保存为.bat
文件,然后右键选择用管理员身份运行。