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
New to the batch - Folder removal
Moderator: DosItHelp
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
Re: New to the batch - Folder removal
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
)
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
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
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".
or avery_larry's suggestion
Regards
aGerman
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
w/o del:
Code: Select all
pushd %userprofile%\Application Data\Sun\Java&& rd /s/q .