New to the batch - Folder removal

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ToxicT
Posts: 3
Joined: 04 Jun 2010 05:48

New to the batch - Folder removal

#1 Post by ToxicT » 04 Jun 2010 05:53

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

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: New to the batch - Folder removal

#2 Post by aGerman » 04 Jun 2010 07:02

Try this

Code: Select all

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


Regards
aGerman

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

Re: New to the batch - Folder removal

#3 Post by avery_larry » 04 Jun 2010 08:39

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
)

ToxicT
Posts: 3
Joined: 04 Jun 2010 05:48

Re: New to the batch - Folder removal

#4 Post by ToxicT » 04 Jun 2010 09:03

Thank you all :)

ToxicT
Posts: 3
Joined: 04 Jun 2010 05:48

Re: New to the batch - Folder removal

#5 Post by ToxicT » 09 Jun 2010 08:32

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

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: New to the batch - Folder removal

#6 Post by aGerman » 09 Jun 2010 10:15

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

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: New to the batch - Folder removal

#7 Post by amel27 » 13 Jun 2010 23:37

w/o del:

Code: Select all

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

Post Reply