Code Preview
copy *.csv all.csv #For flatten file structure 單一資料夾檔案合併 for /R %f in (*.txt) do type "%f" >> all.txt #For merging sub-folder files 多層資料夾檔案合併
There are lots of use cases that we have to handle numbers of fragment files . One of the the common operation is to combine text files into a single file. You may find section below helpful if you have to merge multiple text files.
Scenario
Case A : Combine csv data feed into single Excel sheet for filtering and analysis.
Case B : Collect all intranet system log for investigation .
The task is easy but can be time consuming , and the task actually can be done using command line within 3s. There are mainly two ways to combine text files in command line.
Method 1
The simple way is using copy command for NO sub-directory file case
![]() |
| Flatten file structure |
copy *.csv all.csv
Result
The Command above mainly choose the files to merge in the folder by selecting file extension .
It tells window to merge all .csv file in folder "C:/Users/Local User/Documents" into a file named as "all.csv".
Alternatively, you may also use the wildcard symbol * in file name like below :
The command
copy b*.csv b_all.csv
Result
The command merge .csv files with prefix letter "b" in filename into file named as "b_all.csv".
Method 2
The customized way is using for /R to handle recursive selection in sub-directory

for /R %f in (*.txt) do type "%f" >> allLog.txt
Result




No comments:
Post a Comment