Batch delete: Access is denied
To force a del
command to delete read-only files, add the /F
flag.
Apparently, a read-only file cannot normally be deleted by a batch file, although it can still be deleted through Windows Explorer. To check if your file is read-only, you can right click on the file and select properties, or enter attrib <filename>
at the command prompt. This will show a series of letters corresponding to different file attributes.
R = Read-only file
A = Archive file
S = System file
H = Hidden file
You can remove the read-only tag by unchecking the box in the properties window or running the command attrib <filename> -R
.
After experimenting with the options available to the "del" command I discovered that the files I was attempting to delete were read-only. To resolve the problem I could either edit the files to remove the read-only attribute, or specify the /F option.
Final script is
set destPath=\\Public01\Appl\CompOps\Jobs\
robocopy . "%destPath%" *.dtsx *.dev *.prod *.ppro /IS
pushd "%destPath%"
del /F *.dtsConfig
ren *.dev .
popd
Simple solution, but a misleading error message. Hopefully this helps someone else.