1

我在目录“C:\Paypal_EMT\data”中有许多 CSV 文件,我需要根据第一列处理和提取某些数据列。

但我收到以下错误“系统找不到文件 C:\Paypal_EMT\data\STL-20130614.01.005.CSV”

C:\Paypal_EMT\data\STL-20130614.01.005.CSV
C:\Paypal_EMT\data\STL-20130615.01.005.CSV
C:\Paypal_EMT\data\STL-20130616.01.005.CSV
....

And data file looks as follows:
"RH",2013/06/15 02:14:58 -0400,"X","LQ3SUEEWPWKL6",005,
"FH",01
"SH",2013/06/14 00:00:00 -0400,2013/06/14 23:59:59 -0400,"LQ3SUEEWPWKL6",""
"CH","TransactionID","InvoiceID","PayPalReferenceID","PayPalReferenceIDType","TransactionEventCode","TransactionInitiationDate","TransactionCompletionDate","TransactionDebitOrCredit","GrossTransactionAmount","GrossTransactionCurrency","FeeDebitOrCredit","FeeAmount","FeeCurrency","CustomField","ConsumerID","PaymentTrackingID"
....

Here's my code so far:

@echo off
setlocal EnableDelayedExpansion

:: Set path directory where csv files reside in variable
Set _InputPath=C:\Paypal_EMT\data

FOR %%I IN (!_InputPath!\*.CSV) DO ( 

   Set "_OutFile=%%I.sum.rpt"

   FOR /F "tokens=1-18* delims=," %%A IN (!I!) DO (
     if "%%~A"=="RH" echo %%~B
     if "%%~A"=="FH" echo %%~B
     if "%%~A"=="SH" echo %%~B
     if "%%~A"=="CH" echo %%~B,%%~Q,%%~R
     if "%%~A"=="RF" echo %%~B,%%~Q,%%~R
    )

) > %_OutFile%
4

1 回答 1

2

尝试这个:

@echo off
setlocal EnableDelayedExpansion

:: Set path directory where csv files reside in variable
Set "_InputPath=C:\Paypal_EMT\data"

FOR %%x IN ("%_InputPath%\*.CSV") DO ( 

   Set "_OutFile=%%~x.sum.rpt"

   (FOR /F "usebackq tokens=1-18* delims=," %%A IN ("%%~x") DO (
     if "%%~A"=="RH" echo %%~B
     if "%%~A"=="FH" echo %%~B
     if "%%~A"=="SH" echo %%~B
     if "%%~A"=="CH" echo %%~B,%%~Q,%%~R
     if "%%~A"=="RF" echo %%~B,%%~Q,%%~R
    ))>"!_OutFile!"
) 
于 2013-07-05T15:25:38.333 回答