I have a zip folder, under that I have many sub folders and each sub folder has some csv files. Now i want to copy (merge) all the csv files from different sub folders into one csv file... by using only batch scripting
1 Answer
The code below searches through subdirectories with DIR /S looking for .csv files. Upon finding one, it appends the contents to the file named in the SUMMARY_FILE variable.
SETLOCAL ENABLEDELAYEDEXPANSION
SET SUMMARY_FILE=C:\Users\bone\sumfile.csv
IF EXIST "%SUMMARY_FILE%" (DEL "%SUMMARY_FILE%")
CD C:\root\of\all\csv\files
SET /A LINE_COUNT=1
FOR /F "usebackq tokens=*" %%f IN (`DIR /S /B *.csv`) DO (
FOR /F "usebackq tokens=*" %%s IN (`TYPE "%%~f"`) DO (
ECHO !LINE_COUNT!,%%s >>"%SUMMARY_FILE%"
SET /A LINE_COUNT=!LINE_COUNT! + 1
)
)
EXIT /B 0
-
Mogsdad the solution provided by u is excellent... and now I am in need of one more requirement i.e. after this merging I need a new column saying S.No. and it should contain values starting from 1,2,3.... to number of rows– PrasadOct 26, 2015 at 12:35
-
-
-
@Liturgist - Actually its not working... script looks good, seems it require little bit of changes. Working on that.....– PrasadOct 27, 2015 at 10:52
-
@Mogsdad - could u pls hlp me with the new requirement, which I have mentioned in above comments...Thanks in advance– PrasadOct 29, 2015 at 11:38