Copying the contents of one or more word document into another word document

Welcome Forums General PowerShell Q&A Copying the contents of one or more word document into another word document

This topic contains 3 replies, has 4 voices, and was last updated by

 
Participant
2 months, 1 week ago.

  • Author
    Posts
  • #165577

    Participant
    Topics: 3
    Replies: 3
    Points: 43
    Rank: Member

    Hi,

     

    I am trying to use the following command:

    gc  03.docx | sc c:\Test\04.docx

     

    but when it creates the file 04.docx, it can't be opened by Microsoft Word. Please help.

  • #165595

    Senior Moderator
    Topics: 8
    Replies: 1041
    Points: 3,439
    Helping Hand
    Rank: Community Hero

    What are you trying to achieve here. If your intend is to change extension, you should use Rename-Item cmdlet.

    Get-Help Rename-Item -Online

    btwn, just changing the extension doesn't make doc to docx, i believe.

  • #165598

    Participant
    Topics: 1
    Replies: 1530
    Points: 2,591
    Helping Hand
    Rank: Community Hero

    Please format your code as code using the code tag button (pre) provided. Thanks.

    Why don't you simply copy the complete file?

    Copy-Item -Path 03.docx -Destination c:\Test\04.docx
  • #165658

    Participant
    Topics: 1
    Replies: 59
    Points: 328
    Helping Hand
    Rank: Contributor

    So, docx is format file (not plain text), for a 'test' go ahead and do get-content 03.docx. What you'll notice is a LOT of gibberish to the screen.

    If you want to save multiple .docx files to a new docx file, you're going to need to be able to read the document properly first. There are some conversations of doing this online.

    https://blogs.technet.microsoft.com/bshukla/2010/07/28/how-to-convert-a-word-document-to-other-formats-using-powershell/

You must be logged in to reply to this topic.