delete files in a folder but not subfolders

Welcome Forums General PowerShell Q&A delete files in a folder but not subfolders

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years ago.

  • Author
  • #5792

    Points: 0
    Rank: Member

    by willbs at 2013-04-10 12:53:50

    i have this command for example

    remove-item -path C:\serverfolders\users\*

    i want to delete all of files in the "users" folder but i don't want to delete any subfolders whose names are unknown to me, any ideas?
    is there an -exclude folders type command?

    by ArtB0514 at 2013-04-10 12:59:21

    Version 2:
    Get-Childitem C:\serverfolders\users\* | Where-Object {-Not $_.PSIsContainer} | Foreach-Object {Remove-Item $_.FullName}

    Version 3:
    Get-Childitem C:\serverfolders\users\* -File | Foreach-Object {Remove-Item $_.FullName}

    by willbs at 2013-04-10 13:40:25

    that's a bingo, thanks Art

    by ArtB0514 at 2013-04-10 13:44:43

    You're very welcome.

The topic ‘delete files in a folder but not subfolders’ is closed to new replies.