trying to delete a dir...

March 12, 2009 at 20:05:35
Specs: Windows Vista Ultimate SP1 x64
I am trying to delete a directory that is not empty.

The batch file looks like this:

@echo off
set /p gamedir=<"hl_dir.txt"
rd /s /q "%gamedir%"
pause
exit

And it gives this output:

The directory is not empty.
Press any key to continue . . .


What am I doing wrong? :\


See More: trying to delete a dir...

Report •


#1
March 12, 2009 at 22:55:18
It looks like you're doing it right, unless it's something weird in Vista.


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
March 13, 2009 at 00:48:09
Try the Del command instead of Rd.

Report •

#3
March 13, 2009 at 04:03:15
The directory is not empty.
Translation: RD could not remove some file. Either because you don't have the required delete permissions, or (more likely) some file/directory is in use.

Report •

Related Solutions

#4
March 13, 2009 at 04:12:42
I found what was making this problem.

The hl_dir.txt file was supposed to contain the path
to the dir that needs to be removed.

The path was stored in hl_dir.txt using:

echo %CD% >"..\hl_dir.txt"

and this line had an error.
It was supposed to look like this:

echo %CD%>"..\hl_dir.txt"

that space between % and > resulted in %gamepath% having the value "C:\Games\game "

Notice that space before last quotes.
It was the reason for not being able to delete a dir.


Report •

#5
March 13, 2009 at 04:40:37
Everyone, thanks for help.

Report •

#6
March 13, 2009 at 15:50:44
Here's a little tip, make a directory with the very last character a number and the second last a space(e.g. "c:\test 2") and then try your line:

echo %CD%>"..\hl_dir.txt"

Because of output redirection any number that is to the left of the ">" will be interpreted as redirecting one output into another. One way to avoid this is to do the redirection before the command.

>"..\hl_dir.txt" echo %CD%


Report •

#7
March 13, 2009 at 16:12:35
Useful tip indeed, thanks Judago. :)

Report •

#8
March 14, 2009 at 02:48:51
Hi Judago,

Good stuff

For the simple cases you can nevermind the ECHO:

cd>somefile

And yeah, a space is a char [20 hex] even though it's hard to see LOL


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#9
March 14, 2009 at 03:55:09
or you can surround the echo statement inside hmmm, how do you spell this thing "(" and ")" ?

(echo c:\test 2)>test.txt


Report •

#10
March 14, 2009 at 03:56:47
Hi M2,

Didn't even think of "cd>somefile", it's funny how easy it is to be blinded by example ;).


Report •

#11
March 14, 2009 at 06:08:52
Reno,

"how do you spell this thing "(" and ")" ?"
Brackets?

I also know of 2 other ways:

cmd /c "echo c:\test 2">file
echo c:\test ^2>file

Using brackets has a drawback almost as bad as the later above, if you want to echo a closing bracket you would need to escape it with a carat.

i.e

(echo (dir1) c:\test 2)>file
vs
(echo (dir1^) c:\test 2)>file


Report •


Ask Question