delete files in a folder but not subfolders

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

  • Author
    Posts
  • #5792

    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.

You must be logged in to reply to this topic.