Command to delete files on a UNC path

Hi, I tried the command below to delete files along the UNC path

set folder="\\SERVERNAME\Publish" cd /d %folder% for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q) 

But I got an error message:

 UNC paths are not supported. Defaulting to Windows Directory 

Somehow I need to delete files that are in the server sharing path using a command command. Any help was appreciated.

+6
source share
1 answer

edited 2015-09-16 - the original answer remains below

The code is reformatted to avoid deleting unwanted folders when display fails. Only if pushd is being executed is deletion performed.

 set "folder=\\SERVERNAME\Publish" pushd "%folder%" && ( for /d %%i in (*) do rmdir "%%i" /s /q popd ) 

original answer:

 set "folder=\\SERVERNAME\Publish" pushd "%folder%" for /d %%i in (*) do rmdir "%%i" /s /q popd 

pushd will create a disk mapping along the unc path and then change to it. Then all operations are performed on the disk: \ folders. At the end of popd will be deleted.

+9
source

All Articles