none
Or operation with a regular expression fails. RRS feed

  • Question

  • I have a array of a directory listing.  This listing has the full path of files.  It want to delete trivial files like "Thumbs.db" and *.temp and *.tmp.  I just use the -notmatch operator with a regular expression with a variable "$skip" as shown below

    $Skip = '(.*\\Thumbs.db$)|(.*\.temp$)|(".*\.tmp$)'

    $changedfiles = $changedfiles | where { $_.fullpath -notmatch $skip }

    This does delete the "Thumbs.db" listings but the "*.tmp" and "*.temp" files still get through.  I can't find the exact definition of "|" so I question if I am using it correctly.

    Thanks for any help.

    Saturday, May 18, 2019 12:07 PM

Answers

  • JRV,

    Thanks for your help.  You guided me to the correct expression.

    $skip = '\\Thumbs.db|\.temp$|\.tmp$'

    the "$" was needed to prevent it matching parent directories.  Also Thumbs.db would be proceeded with a  "\".

    Thanks for you help.

    • Marked as answer by dga_1 Monday, May 20, 2019 6:00 PM
    Monday, May 20, 2019 6:00 PM

All replies

  • $Skip = '\.Thumbs.db|\.temp|\.tmp'


    \_(ツ)_/

    Saturday, May 18, 2019 4:58 PM
  • JRV,

    Thanks for your help.  You guided me to the correct expression.

    $skip = '\\Thumbs.db|\.temp$|\.tmp$'

    the "$" was needed to prevent it matching parent directories.  Also Thumbs.db would be proceeded with a  "\".

    Thanks for you help.

    • Marked as answer by dga_1 Monday, May 20, 2019 6:00 PM
    Monday, May 20, 2019 6:00 PM