UNC path is not supported error

I recently had an issue running a batch file using a UNC path and discovered that UNC paths are not always supported. This failed in the following line.

ForFiles /p "\\Server\folder\username\SQLBackups" /s /d -13 /c "cmd /c del /q @file"

The solution was to use PUSHD and POPD as shown here

:: Create a temporary drive letter mapped to your UNC root location
:: and effectively CD to that location
pushd \\Server\folder\username

:: Do your work
ForFiles /p "SQLBackups" /s /d -13 /c "cmd /c del /q @file"

:: Remove the temporary drive letter and return to your original location
popd

Explained here: windows - How to run batch file from network share without "UNC path are not supported" message? - Stack Overflow

Add comment

Loading