Deleting file containing specific path

Welcome Forums General PowerShell Q&A Deleting file containing specific path

Viewing 1 reply thread
  • Author
    Posts
    • #220032
      Participant
      Topics: 6
      Replies: 8
      Points: 76
      Rank: Member

      Hi Forum!

      Does anyone know, if it is somehow possible to target files, that contains a path name accross multiple directories?

      For an example:

      Folder:/
      Domain.com/content/system/unwanted/malicious.php
      Domain.com/content/assets/objects/unwanted/anothermalicious.php

      Is it possible to create a deletion process that scans the paths of all files, and then deletes them if the path contains unwanted?

      Currently i have no example of code to execute this, i am struggling to find documentation regarding if this is even possible.

      Can anyone point me in the right direction? 🙂

      Best regards
      Jonatan

    • #220038
      Senior Moderator
      Topics: 8
      Replies: 1215
      Points: 4,335
      Helping Hand
      Rank: Community Hero

      you can always use Get-ChildItem with -Filter parameter. Below is an example.

      Get-ChildItem -Path c:\RootFolder -Filter *unwanted* -Recurse -Directory
      

      Save the output of the above expression in a variable and process further for deletion.

      I suggest to read the help doc of Get-ChildItem and Remove-Item cmdlet.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.