• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 710
  • Last Modified:

.bat file to delete folder from All Users Profile

Hello Experts,
I know this has probably been asked before,  and I'm not sure if I'm asking in the right zone, but how in the world do you delete a folder from the All Users Profile in a batch file in XP Pro? I have tried all sorts of ways but to no avail.
For example, to delete a folder named "DeleteTest" from the %ALLUSERSPROFILE%\Documents folder, how could I code that? I did find a little code on here that went something like this:

%SystemDrive%
cd \
cd %ALLUSERSPROFILE%\Documents
del "DeleteTest"

However, I played around with it but couldn't get it to work.


Thanks in advance...RunForrestRun
0
RunForrestRun
Asked:
RunForrestRun
  • 9
  • 6
1 Solution
 
SteveGTRCommented:
del "%ALLUSERSPROFILE%\Documents\DeleteTest" /q /s

The key is the double quotes around the directory since it has spaces in it.
0
 
RunForrestRunAuthor Commented:
Hi Steve,
Many thanks,
I tried it with just this one line that you gave here, but it still didn't work, should I add in this other stuff like below:

%SystemDrive%
cd \
cd %ALLUSERSPROFILE%\Documents
del "%ALLUSERSPROFILE%\Documents\DeleteTest" /q /s

RFR
0
 
SteveGTRCommented:
All that code is unnecessary because the path is fully qualified by ALLUSERSPROFILE.

Questions:

1) When you said it didn't work. What did you mean? Did you get error messages or any information from DOS?

2) What happens when you do this:

echo %ALLUSERSPROFILE%

3) Does this display any files?

dir "%ALLUSERSPROFILE%\Documents\DeleteTest"

Please answer these questions. Thanks :)
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
RunForrestRunAuthor Commented:
Steve I'm sorry, man you answer fast. (-:
Okay,
with just the one line:

del "%ALLUSERSPROFILE%\Documents\DeleteTest" /q /s

all it does is just pop open the cmd window for a split second and closes.

And with this line same thing:

echo %ALLUSERSPROFILE%

Same thing with this line:

dir "%ALLUSERSPROFILE%\Documents\DeleteTest"

I can stop it with the pause button on my keyboard but man I have to be FAST. But it's basically doing the same thing with either 3 lines that I have in there.

0
 
RunForrestRunAuthor Commented:
Oh one more thing, and it's still not deleting the file...
0
 
SteveGTRCommented:
Open a command window and repeat the tests. You can do this by doing Start --> Run --> enter cmd and click OK.
0
 
RunForrestRunAuthor Commented:
Okay I hope I did this right.
I opened up my cmd window and put in the lines one at a time and clicked OK. But after each one I would get a window that popped up and said:
Windows cannot find 'del'. Make sure you typed the name correctly, and then try again.
And then:
Windows cannot find 'echo'. Make sure you typed the name correctly, and then try again.
And then:
Windows cannot find 'dir'. Make sure you typed the name correctly, and then try again.

Let's see were you wanting me to put in each line starting with:

del "%ALLUSERSPROFILE%\Documents\DeleteTest" /q /s
0
 
RunForrestRunAuthor Commented:
I'm sorry Steve what I meant was I tried one line at a time and clicked OK. I know I didn't make my self too clear there at the end.
0
 
SteveGTRCommented:
I was confused by you prior statement:

-----
del "%ALLUSERSPROFILE%\Documents\DeleteTest" /q /s

all it does is just pop open the cmd window for a split second and closes.
-----

Specifically, the "all it does is just pop open the cmd window for a split second and closes.

That would indicate that you were not running the commands from the cmd box.

Do you understand what I mean by cmd box? Please follow the instructions I posted to open a cmd box and try again.
0
 
RunForrestRunAuthor Commented:
I'M SORRY Steve, I TOTALLY misunderstood,
I DIDN'T have the cmd window open, I was just going Start-->Run and trying to run these tests from the Run command. Now I opened the right cmd window and pasted all the tests in one at a time and hit enter.
The first test didn't return anything.
The second test returned C:\Documents and Settings\All Users
The third test returned this directory information:
 Volume is Drive C has no label
 Volume serial number is xxxx-xxxx
 Directory of C:\Documents and Settings\All Users\Documents\DeleteTest
11/06/2007 11:31 AM <DIR>
11/06/2007 11:31 AM <DIR>
                     0 files 0 bytes
                    2 Directories 2 gazillion bytes blah blah blah all that stuff when you do a dos like dir

I deeply apologize my bad
0
 
RunForrestRunAuthor Commented:
Steve I really appreciate all your help.
Sorry you had to spend so much time dealing with my mess.
Hope you have a wonderful Thanksgiving. (-:

RFR
0
 
SteveGTRCommented:
Thanks :)

I looks like the del command worked fine. It won't clear out the directories. The easiest way to do it is via rd:

rd "%ALLUSERSPROFILE%\Documents\DeleteTest" /q /s

Of course that gets rid of DeleteTest as well. If you need that directory, than just recreate it:


mkdir "%ALLUSERSPROFILE%\Documents\DeleteTest"
0
 
RunForrestRunAuthor Commented:
Hi Steve,
back from the Thanksgiving holiday. THAT DID IT!! 500 for you buddy. Thank you SOOO much. Tried it first thing this morning and went off without a hitch. I even went in there and recreated the DeleteTest folder ran my batch file again just to see, and deleted it oh so smoothly.

God Bless

RFR
0
 
RunForrestRunAuthor Commented:
Good Morning Steve,
back from the Thanksgiving holiday and I want you to know I tried that and it went off without a hitch. You are a genius. I even went in there and recreated the DeleteTest folder, ran my batch file again and it deleted it without a problem. 500 points for you buddy. I really appreciate all your help. Say, I tried to award points for you but it said this was already accepted. Well anyway 500 for you in my book. (-: God Bless and hope you had a wonderful holiday.

RFR
0
 
SteveGTRCommented:
Thanks :) Glad to help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 9
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now