Solved

.bat file to delete folder from All Users Profile

Posted on 2007-11-21
15
612 Views
Last Modified: 2010-04-21
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
Comment
Question by:RunForrestRun
  • 9
  • 6
15 Comments
 
LVL 30

Expert Comment

by:SteveGTR
ID: 20330567
del "%ALLUSERSPROFILE%\Documents\DeleteTest" /q /s

The key is the double quotes around the directory since it has spaces in it.
0
 

Author Comment

by:RunForrestRun
ID: 20330943
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
 
LVL 30

Expert Comment

by:SteveGTR
ID: 20330963
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:RunForrestRun
ID: 20331235
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
 

Author Comment

by:RunForrestRun
ID: 20331240
Oh one more thing, and it's still not deleting the file...
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 20331290
Open a command window and repeat the tests. You can do this by doing Start --> Run --> enter cmd and click OK.
0
 

Author Comment

by:RunForrestRun
ID: 20331383
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
 

Author Comment

by:RunForrestRun
ID: 20331394
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
 
LVL 30

Expert Comment

by:SteveGTR
ID: 20331423
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
 

Author Comment

by:RunForrestRun
ID: 20331507
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
 

Author Comment

by:RunForrestRun
ID: 20331795
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
 
LVL 30

Accepted Solution

by:
SteveGTR earned 500 total points
ID: 20332712
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
 

Author Closing Comment

by:RunForrestRun
ID: 31410976
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
 

Author Comment

by:RunForrestRun
ID: 20350150
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
 
LVL 30

Expert Comment

by:SteveGTR
ID: 20350169
Thanks :) Glad to help.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
preview video of network plus 2 117
Xcopy / Robocopy Question 7 66
Event ID: 1008 / Source: Microsoft-Windows-Perflib 2 166
Batch/VBScript : Disable Windows tasks 7 35
Step by step guide to Clean and Sort your windows registry! Introduction: Always remember: A Clean registry = Better performance = Save your invaluable time In this article we're going to clear our registry manually! Yes, manually! The e…
If you have done a reformat of your hard drive and proceeded to do a successful Windows XP installation, you may notice that a choice between two operating systems when you start up the machine. Here is how to get rid of this: Click Start Clic…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question