Question:
How do I use Command Prompt to delete a folder?
imthefrere
2009-08-19 07:56:09 UTC
I'm trying to create a batch file to delete everything in my temp upon starting windows. Sure I could use a program for this, but batch files are small and I don't want to slow down my boot speed anymore. I've been getting somewhere but I'm still having a few problems.

Note: I'm using the command "del (file name) /s"

1 When I try to delete the folder
C:\Documents and Settings\Jilly\Local Settings\temporary internet files

I get the error "Could not find C:\Documents and Settings\Jilly\Local Settings\temporary"
I assume this is because the file has spaces, but I tried using underscores and it still couldn't find the folder.

2 When I try to delete the history, it says "Cannot access the file because it is being used by another process" How do I bypass this error?

Oh and one more thing I think might create a problem. I want this file to run on startup automatically and finish by itself, but I think when you're about to delete a file it asks for your permission, how do I get past this? I was thinking adding y under it in notepad might work when I'm writing it, but it might ask for permission for each file, how can I get around all this?

Thanks for your time
Three answers:
FullMetal
2009-08-19 08:05:52 UTC
Since you have spaces between some of the words you will need to put " " around the whole path.



Try using this command in your batch file:



del "C:\Documents and Settings\Jilly\Local Settings\temporary internet files\*.*" /f /s /q



The /f switch will force the deletion.



The /s switch will delete files in all subdirectories.



The /q switch will do it in quiet mode without asking for user input.



I added the *.* in the path to delete "all" files.



Hope this helps!
Jim Maryland
2009-08-19 08:55:26 UTC
Use:



dir /x



to show the 8.3 name of the folder. This will simplify the names so that you don't need to worry about spaces (ex: "C:\Program Files" becomes "C:\Progra~1").



For files in use, good luck with that. Apparently Microsoft "knows better" than you about what files can and can't be deleted. (OK, you can look for an app called SysInternals on the Microsoft site, but this won't necessarily help your batch script. It can be used to remove file handles with a process so a file can be deleted. Manual process, can't be scripted that I know of.)



For deleting read-only files, look at:



del /F



to force deleting read-only files.



Another option is to use:



rmdir /sq



The "s" removes all directories and files in the specified directory and the "q" says to go about doing so quietly (no prompts).
?
2009-08-19 08:03:57 UTC
Change it to

Del C:\"Documents and Settings"\Jilly\"Local Settings"\"temporary internet files"\*.* /s





You need to put the long words in quotes.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...