Solved

.bat file to delete folder from All Users Profile

Posted on 2007-11-21
15
601 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
 

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now