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

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -