we have an ftp server with 50 users, they have a main folder(as below) and 5 sub folders. I am looking for a script that will clean the contents of the sub folders on a weekly basis. However not touch the archive folder in the sub folders and do this for all the 50 users.

C:\ftp\ftp-users jmartin -- jmartin-a1 jmartin-a2 jmartin-a3 jmartin-a4 jmartin-a5 archive


You requested Powershell so here you go. Just change the C:\Folder to wherever you need. This script will get a list of folders in the root, then a list of files/folders in those folders and delete them.

Get-ChildItem -path C:\Folder\ | ?{ $_.PSIsContainer } | Foreach-Object{
    $_ | Get-ChildItem -Recurse | Remove-Item

This can be expanded. Say I have the structure


I could use the following to delete anything in the Nick1, Nick2, Bob1, Bob2 folders (Including folders) but leave the preceding structure in place. If I wanted to remove the Bob1, Bob2, Nick1, and Nick2 folders I would use the first command (Above) that would leave only Nick and Bob folders in place.

Get-ChildItem -path C:\Folder\ | ?{ $_.PSIsContainer } | Foreach-Object{
    $_Get-ChildItem | ?{ $_.PSIsContainer } | Foreach-Object{
        $_ | Get-ChildItem -Recurse | Remove-Item

you could compress this down to a one liner

Get-ChildItem -path C:\Folder\ | ? { $_.PSIsContainer } | Get-ChildItem | ? { $_.PSIsContainer } | Get-ChildItem -Recurse | Remove-Item

Try this one:

For /R C:\ftp\ftp-users %G IN (.) do del "%G" /q

remember: when you want to use it in a batch put instead of one % two of them.

For /R C:\ftp\ftp-users %%G IN (.) do del "%%G" /q

Kind regards,



You can always try:

del /s /q C:\FTP\*.*

or delete all files in sub-dirs without Archive attribute:

del /s /q /a:-a C:\FTP\*.*

Here some info:

  /A            Selects files to delete based on attributes
  attributes    R  Read-only files            S  System files
                H  Hidden files               A  Files ready for archiving
                I  Not content indexed Files  L  Reparse Points
                -  Prefix meaning not

It will find and delete all files in sub-directories in C:\FTP\

Add this to windows scheduler as:


with params:

/c del /s /q C:\FTP\*.*

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.