powershell - Combine text from multiple files into a single file -


i'm trying create text file contains content of source code files concatenated. i've came following concise code:

get-childitem  -recurse mysourcepath -include "*.htm", "*.cs" | foreach-object  {get-content $_.fullname | add-content myfile.txt} 

the problem is, after multiple files (hundreds or thousands), i'm starting following error:

add-content : process cannot access file 'myfile.txt' because being used process.

it seems concurrency issue , thought related pipelining mechanism, using foreach didn't solve problem.

what right way in powershell protect file multiple writes? there way still utilize pipeline?

as explained here, problem add-content, it

get-childitem $mysourcepath -recurse -include "*.htm", "*.cs" | get-content |  out-file -append myfile.txt    #short version gci -file $mysourcepath -recurse -include "*.htm", "*.cs" | gc >>  myfile2.txt 

Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -