remove more than one folder

Welcome Forums General PowerShell Q&A remove more than one folder

Viewing 2 reply threads
  • Author
    Posts
    • #263600
      Participant
      Topics: 1
      Replies: 0
      Points: 11
      Rank: Member

      hi, I am having trouble in removing more than a folder, I tried:

      but I got the error:

      • This topic was modified 3 days, 23 hours ago by cimerio84.
      • This topic was modified 3 days, 23 hours ago by cimerio84.
      • This topic was modified 3 days, 21 hours ago by grokkit.
    • #263669
      Senior Moderator
      Topics: 10
      Replies: 182
      Points: 968
      Helping Hand
      Rank: Major Contributor

      Remove-Item only accepts one path at a time.

      If you want to remove everything stored in tempS9 you can use a wildcard like this:

      but be careful because this will remove everything in that directory.

      If you need to remove specific items in that directory then the easiest thing to do is store the names of the things you want to remove in an array and then use a foreach loop to apply Remove-Item to each one.

      Also, if your file path actually has a # symbol in it as shown in your command then you will need to wrap the path in quotes like this:

      It’s generally safer to wrap paths in quotes to ensure that they are interpreted correctly.

    • #263690
      Participant
      Topics: 5
      Replies: 331
      Points: 536
      Helping Hand
      Rank: Major Contributor
Viewing 2 reply threads
  • You must be logged in to reply to this topic.