Forum Discussion

Nicktab's avatar
Nicktab
Copper Contributor
May 25, 2023

wordconv - unable to exclude .docx

Hello everyone,

 

below you can find my script. i can't exclude .docx. I tried without wipe whereobject etc or with it, but anyway, .docx are still in the variable $FILEDOC .... i'm missing something but i can't figured out it

 

Can you help me please?

 

 

 

 

 

 

 

$LOGPATH= "C:\dir\logword.txt"


$PERCORSO = Read-Host "where are .doc?"

$FILEDOC = Get-ChildItem -LiteralPath "$PERCORSO" -name -File -Filter *.doc | Where-Object fullname -NotLike "*.docx"

 

 

 

 

 

 

 

 

  • I changed the last line to the line below, which will get you all the *.doc files. Added the -Recurse the scan all subfolders you can remove if you don't need that.

     

    $FILEDOC = Get-ChildItem -LiteralPath "$PERCORSO" -Name -File -Include *.doc -Recurse

     

     

    • Nicktab's avatar
      Nicktab
      Copper Contributor

      Harm_Veenstra

      Hello,

       

      does it works for you?

      i tried it -> no way. in my $FILEDOC there are .docx .ps1 file, not only .doc 

      • Nicktab 

        I created a test folder with a docx and doc file:

         

        When I run this, I only get the docx file:
        C:\Users\HarmVeenstra> Get-ChildItem -LiteralPath d:\temp\test -Recurse -Include *.docx -name
        New Microsoft Word Document.docx

        When I run this, I only get the doc file:

        C:\Users\HarmVeenstra> Get-ChildItem -LiteralPath d:\temp\test -Recurse -Include *.doc -name
        New Microsoft Word Document.doc


        So the -Include doc does work in my opinion 🙂