Match Recycle Bin path

This topic contains 1 reply, has 2 voices, and was last updated by  Daniel Krebs 2 years, 1 month ago.

  • Author
    Posts
  • #28434

    Clum09
    Participant

    Hello,

    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'
    [regex]::match($path,"[C-Z]:\\\`$.*").value

    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

    Daniel Krebs
    Moderator

    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'
    [regex]::match($path,'[C-Z]:\\\$.*').value

You must be logged in to reply to this topic.