Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

As the title suggests, 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

Update 1: Tried running as administrator, still the same issue

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

You may have to run the batch file as administrator. Right click on the file and click "Run as Administrator", and see if it runs successfully that way.

Edit: 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 then remove the read-only tag by unchecking the box in the properties window or running the command attrib <filename> -R.

To force a del command to delete read-only files, add the /F flag.

share|improve this answer
    
unfortunately that does not fix the problem, i'll update my question to include your suggestion though. –  shiznit123 Dec 7 '11 at 20:05
    
Try putting pause before the del command, and then try deleting it through Windows Explorer while it's paused. –  SaintWacko Dec 7 '11 at 20:11
    
I found the solution, however if you wish to edit your answer to include some suggestions in addition to my solution I'd be happy to mark it as the answer –  shiznit123 Dec 7 '11 at 20:15
    
Alright, is that information retroactively helpful? :) –  SaintWacko Dec 7 '11 at 20:37
    
I'm sure it will be helpful when I forget about this problem months from now :) –  shiznit123 Dec 7 '11 at 20:42
add comment

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.

share|improve this answer
    
If you can only read it, an access denied sounds about right to me. –  surfasb Dec 8 '11 at 6:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.