Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to search a directory with a file extension of .csv. Then once found append the contents to a new .csv file. When I use the pipe I am able to see the .csv file but when I copy the contents to the new file it isn't created with the contents that were originally in the .csv file. Any suggestions?

What I have tried:

This is what I have tried

dir "mydir" | findstr /e .csv > newfile.csv
Posted
Updated 1-Nov-18 5:18am

Use the concatenation output operator ">>":
dir "mydir" | findstr /e .csv >> newfile.csv



Quote:
Yeah I tried that and still got the same result.


Are you sure? Because when I try something very similar it works:
dir . | findstr /e .txt >> newfile.txt
As in:
D:\Temp>cd testdir

D:\Temp\testdir>dir
 Volume in drive D is GriffData
 Volume Serial Number is 4CA5-2F85

 Directory of D:\Temp\testdir

01/11/2018  13:36    <DIR>          .
01/11/2018  13:36    <DIR>          ..
01/11/2018  13:36               652 x.txt
               1 File(s)            652 bytes
               2 Dir(s)  640,177,086,464 bytes free

D:\Temp\testdir>dir . | findstr /e .txt >> newfile.txt

D:\Temp\testdir>type newfile.txt
01/11/2018  13:47                 0 newfile.txt
01/11/2018  13:36               652 x.txt

D:\Temp\testdir>dir . | findstr /e .txt >> newfile.txt

D:\Temp\testdir>type newfile.txt
01/11/2018  13:47                 0 newfile.txt
01/11/2018  13:36               652 x.txt
01/11/2018  13:47                92 newfile.txt
01/11/2018  13:36               652 x.txt

D:\Temp\testdir>
 
Share this answer
 
v2
Comments
Member 13806552 1-Nov-18 9:43am    
Yeah I tried that and still got the same result.
OriginalGriff 1-Nov-18 9:51am    
See updated solution.
Member 13806552 1-Nov-18 10:19am    
Thanks for responding I see what you did there the file names are getting appended to the new file I was hoping to append the actual contents so if x.txt says "hello world" then using the command type newfile.txt will also display "hello world" as well I was searching the extension because the file is self generated and I wont know the name but will only want the contents of it.
OriginalGriff 1-Nov-18 10:43am    
No, you've have to use "type filename.csv" for each file in order to get the content, and that means you need to start looking at batch files or powershell - or simpler, write some code to do it! :laugh:
It's pretty trivial as a C# app for example.
cd "mydir"
FOR %i in (*.csv) DO type %i >> newfile.csv
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900