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: 10
      Replies: 16
      Points: 139
      Rank: Participant

      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: 9
      Replies: 1449
      Points: 5,429
      Helping Hand
      Rank: Community MVP

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

      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
  • The topic ‘Deleting file containing specific path’ is closed to new replies.