Windows – Batch delete: Access is denied

batchcommand linewindowswindows 7

I'm having issues with the del command in a batch file. When it gets to the delete step I get the message "Access is denied". My batch command looks something like this.

set destPath=\\Public01\Appl\CompOps\Jobs\

robocopy . "%destPath%" *.dtsx *.dev *.prod *.ppro /IS

pushd "%destPath%"
del *.dtsConfig
ren *.dev .
popd

Enter image description here

I can browse to the directory and delete the files without any problem in Windows Explorer.

I tried running as administrator, but still the same issue.

Best Answer

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.

Related Question