Match Recycle Bin path

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Daniel Krebs Daniel Krebs 1 year, 2 months ago.

  • Author
  • #28434
    Profile photo of Clum09


    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
    Profile photo of Daniel Krebs
    Daniel Krebs

    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'

You must be logged in to reply to this topic.