Match Recycle Bin path

Welcome Forums General PowerShell Q&A Match Recycle Bin path

This topic contains 1 reply, has 2 voices, and was last updated by

3 years, 9 months ago.

  • Author
  • #28434

    Topics: 6
    Replies: 11
    Points: 0
    Rank: Member


    I need to extract the data from a file path that contains the recycle bin with the regular expression.

    The path is: D:\$RECYCLE.BIN\SubFolder\Subfolder.

    I tried the pattern below, but I cannot extract the path since the dollar sign follows immediately after the back slash character which requires an escape character \.

    The code I have is:

    $path = 'D:\$RECYCLE.BIN\SubFolder\Subfolder'

    I would expect the regex will return the data as variable $path, but it does not. However, if I use [regex]::match($path,"[C-Z]:\\.*").value, I got only D:\.BIN which does not include the whole string.

    How can I set the pattern for the match so that I can get the data assigned to the variable $path?

    Thank you in advance.

  • #28476

    Topics: 2
    Replies: 525
    Points: 24
    Team Member
    Rank: Member

    Below code works for me after removing the backtick and replacing the double quotes of the pattern with singles to prevent PowerShell variable expansion.

    $path = 'D:\$RECYCLE.BIN\SubFolder\Subfolder'

The topic ‘Match Recycle Bin path’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort