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%
嗯 - 我會試圖在自己的內部循環中加入一個USEBACKQ ...想添加兩個「爲什麼它不起作用」? 'Fraid我沒有看到文件名中的點 - 認爲它們是空格......我的specs上有斑點... :( – Magoo
是的,這個被遺忘的'usebackq'是一個非常常見的初學者錯誤,非常感謝你: - )! – Endoro
@Peter - 我測試了更新的代碼,但沒有奏效。我用我的評論編輯了你的文章。再次感謝你的幫助。 – user2550880