11

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.

4 Answers 4

8

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.

6
  • unfortunately that does not fix the problem, i'll update my question to include your suggestion though.
    – agradl
    Commented Dec 7, 2011 at 20:05
  • Try putting pause before the del command, and then try deleting it through Windows Explorer while it's paused.
    – SaintWacko
    Commented Dec 7, 2011 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
    – agradl
    Commented Dec 7, 2011 at 20:15
  • Alright, is that information retroactively helpful? :)
    – SaintWacko
    Commented Dec 7, 2011 at 20:37
  • I'm sure it will be helpful when I forget about this problem months from now :)
    – agradl
    Commented Dec 7, 2011 at 20:42
2

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.

1
  • If you can only read it, an access denied sounds about right to me.
    – surfasb
    Commented Dec 8, 2011 at 6:23
1

What worked for my Windows 8.1 PC:

First of all close Windows Explorer by:

Press Ctrl + Alt + Del for opening Task Manager, go to processes, find Windows Explorer, right click, and end task. Don't worry if start bar is gone and something else. Use Alt + Tab for traversing between files. Then in Task Manager click File and Run new task, and type cmd. This will open you a Command Line.

Inside the Terminal:

If your version is 32 bit, and it is in my case, it's located in Program Files (x86), so you should type:

cd "C:\Program Files (x86)\Git\git-cheetah"
regsvr32 /u git_shell_ext64.dll

This was for unregistering.

You can traverse between directories using cd directoryname and you can get back one directory by cd ... For viewing what is in a directory you can type dir in when you are in that directory. For deleting the file type:

del /F filename

After that again open the Task Manager, go to File, then run explorer . This way you will get to usual display. Go to the Git folder which we wanted to get rid of and delete it simply.

I hope this works for other people who are using Windows 8.1.

0

Had this problem and turned out Avast was denying my batch file. All I had to do was add the .bat file to the exception list on Avast.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .