Re: Removing all content except for a particular folder
Hi all,
I was able to find a work around. I am posting this for anyone in the future who has the same problem:
Instead of using the rm command which does not support masks (but does support wildcards) you can use a synchronize command to remove all of the files on the remote server.
Command 1: synchronize remote -delete -filemask="|folder-without-write-access/" "C:/intentionally-empty-directory"
This command removes the content from the remote server. folder-without-write-access is the folder that you want to avoid trying to overwrite/remove and C:/intentionally-empty-directory is an intentionally empty folder that you need to create locally so that when WinSCP runs the synchronize command it synchronizes an empty folder, ie it removes the content from the server (except for the folder-without-write-access folder) as desired.
Command 2:
synchronize remote -filemask="|folder-without-write-access/" "C:/directory-containing-content-to-deploy"
This command deploys your new content to the remote server. folder-without-write-access is the folder that you want to avoid trying to overwrite and C:/directory-containing-content-to-deploy is a folder that contains the content that you want to deploy to the server. The "-filemask" here is not necessarily needed, but it will avoid the script failing if you end up with a folder named folder-without-write-access inside of C:/directory-containing-content-to-deploy by accident, etc.
I was able to find a work around. I am posting this for anyone in the future who has the same problem:
Instead of using the rm command which does not support masks (but does support wildcards) you can use a synchronize command to remove all of the files on the remote server.
Command 1: synchronize remote -delete -filemask="|folder-without-write-access/" "C:/intentionally-empty-directory"
This command removes the content from the remote server. folder-without-write-access is the folder that you want to avoid trying to overwrite/remove and C:/intentionally-empty-directory is an intentionally empty folder that you need to create locally so that when WinSCP runs the synchronize command it synchronizes an empty folder, ie it removes the content from the server (except for the folder-without-write-access folder) as desired.
Command 2:
synchronize remote -filemask="|folder-without-write-access/" "C:/directory-containing-content-to-deploy"
This command deploys your new content to the remote server. folder-without-write-access is the folder that you want to avoid trying to overwrite and C:/directory-containing-content-to-deploy is a folder that contains the content that you want to deploy to the server. The "-filemask" here is not necessarily needed, but it will avoid the script failing if you end up with a folder named folder-without-write-access inside of C:/directory-containing-content-to-deploy by accident, etc.