Page 1 of 1

New to the batch - Folder removal

Posted: 04 Jun 2010 05:53
by ToxicT
Hi ppl

i have done the following:

cd "%userprofile%\Application Data\Sun\Java"
del *.* /F /S /Q /A: R /A: H /A: A
rmdir /s /q "%userprofile%\Application Data\Sun\Java"
cls

Now this is to remove a load of temp files java puts in there when browsing. I need these removed which is does fine. However i realise that if that folder does not exist. It seems to start deleting files from C:\ drive, seems random, might be desktop might be windows update folder. How do i stop this from a possible C drive nuke :) cheers

Re: New to the batch - Folder removal

Posted: 04 Jun 2010 07:02
by aGerman
Try this

Code: Select all

cd "%userprofile%\Application Data\Sun\Java" || goto :eof


Regards
aGerman

Re: New to the batch - Folder removal

Posted: 04 Jun 2010 08:39
by avery_larry
rd /s /q "%userprofile%\Application Data\Sun\Java"

or if that doesn't work because of hidden/read only files or something:

I guess I don't know if this actually works but:

del "%userprofile%\Application Data\Sun\Java\*.*" /F /S /Q /A: R /A: H /A: A


And finally, an "if exist" would work:

if exist "%userprofile%\Application Data\Sun\Java" (
cd "%userprofile%\Application Data\Sun\Java"
del *.* /F /S /Q /A: R /A: H /A: A
)

Re: New to the batch - Folder removal

Posted: 04 Jun 2010 09:03
by ToxicT
Thank you all :)

Re: New to the batch - Folder removal

Posted: 09 Jun 2010 08:32
by ToxicT
What is interesting though is when i added this to a test login script it managed to delete the contents of all the folders in the mapped H:\my dcouments lol + the right directory :S

Re: New to the batch - Folder removal

Posted: 09 Jun 2010 10:15
by aGerman
If your batch file is on drive H: and you want to switch to another drive (C:) using the "CD" command it will fail without "/d".

Code: Select all

cd /d "%userprofile%\Application Data\Sun\Java" || goto :eof

or avery_larry's suggestion

Code: Select all

if exist "%userprofile%\Application Data\Sun\Java" (
  cd /d "%userprofile%\Application Data\Sun\Java"
  del *.* /F /S /Q /A: R /A: H /A: A
)


Regards
aGerman

Re: New to the batch - Folder removal

Posted: 13 Jun 2010 23:37
by amel27
w/o del:

Code: Select all

pushd %userprofile%\Application Data\Sun\Java&& rd /s/q .