Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

.bat file to delete folder from All Users Profile

Posted on 2007-11-21
15
Medium Priority
?
644 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

704 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