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
Post a Comment