powershell - Copy content form all text files from a directory and write to single text file -
The code below will copy a file of contents from the text file to the directory, but it will overwrite the existing file content:
Go-ChildItem $ FilePath -Recurse-Include * .docx, * folder \ abc \ source.txt | For every object {copy-item $ _. Full name} - Destination C: \ destination.txt}
I want to add all content to the same file.
get content
and add-content
Instead of using copy-item
:
go-babyitem $ filepath -rice-sune * .txt | ? {$ _. Full name-like '* folder \ abc \ source.txt'} | Go-content | Ad-content 'C: \ destination.txt'
Edit: As @Biconbits has correctly told comments for your question, you only Word documents can not be added and text files, because there are previously binary files (a bunch of XML files in which zip archives, in fact). However, if you want only the (text) content of the document to be added, then you can do something like this:
$ wd = New Object - COM 'Word.Application' Get-ChildItem $ FilePath -Recurse | ? {$ _. Extension - That's '.docx' -or $ _. Full name-like '* folder \ abc \ source.txt'} | {%. $ {Doc = Txt '{Get-content $ path}}} | Ad-content 'C: \ destination.txt' $ wd.Quit ()
Note: I get the Get-ChildItem
partial path To work with the -in clude
parameter, I therefore moved those conditions into a where-object
filter.
Comments
Post a Comment