Solved

DOS Batch file

Posted on 2014-07-19
8
617 Views
Last Modified: 2014-07-20
How can I write a BAT file to navigate to

%localappdata%\mydata

and delete the contents

I want to place the file on my WIndows 7 desktop
0
Comment
Question by:JElster
8 Comments
 
LVL 7

Accepted Solution

by:
Raghu Mutalikdesai earned 200 total points
ID: 40206232
Create a new text file on Desktop and name it as, say CleanUp.bat
Right click and select Edit, Notepad opens up
Now paste the following lines and save the file:
@ECHO OFF
CD /D %APPDATA%
DEL /F /S /Q *.*

Open in new window

Double click on the file to run it
0
 
LVL 13

Assisted Solution

by:Norm Dickinson
Norm Dickinson earned 150 total points
ID: 40206238
Launch Notepad

In descriptive terms, you will need to move to the correct folder, then delete.


CD /D %APPDATA%
dir
pause
del *.*
pause

You may want to use the "dir" command to review the file names in the folder and the "pause" command at the end to read any screen output from the DOS window before you get to the delete command, just in case you are accidentally in your system folder and not the intended target folder - that's why I put the first pause command - if it is the wrong content, just X out of the prompt...or say "N" to the delete confirmation prompt. Later, once you know the batch file is working correctly, you can simplify it to only have the following

H:
CD /D %APPDATA%
del /F /S /Q *.*



Save the text file with a name that you like and have it end with .bat instead of .txt.
On that note, open Explorer and look at the file you have created - it may still be a text file depending upon your settings. Go to Organize > Folder and Search Options > View
Uncheck the setting to Hide Extension for Known File Type and apply
Take a second look at the file you created and if necessary rename it to end with .bat and not .bat.txt like it may have been named by Notepad.

Make sure that what you want to delete is not needed and test this batch file carefully - if you delete the wrong folder contents your computer may not boot again.

In fact for general best practices please do a full backup of your system prior to creating this file, if you are not already doing regular backups.
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40206268
Create a new shortcut on the desktop and set this:

cmd.exe /c "echo rmdir /s /q %APPDATA%\mydata" && pause

and give it some useful name.

Note that the above command now only echos what it would delete and halts with a pause, it also deletes the mydata folder.

Also note that the above suggestions that use the del command do not remove subdirectories of mydata.

Do you want the 'mydata' folder removed as well or not?
0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 2

Assisted Solution

by:Parrish Chamberlain
Parrish Chamberlain earned 75 total points
ID: 40206436
Echo OFF

net stop COMSysApp

taskkill /F /IM dllhost.exe

taskkill /F /IM taskhost.exe

taskkill /F /IM taskhostex.exe

del /C %localappdata%\mydata\*.*

net start COMSysApp

echo ON

Save as batch file

1. Copy the batch file to C:\Windows\System32\GroupPolicy\User\Scripts\Logoff folder

2. Run “gpedit.msc” to open “Local Group Policy Editor”

3. Go to User Configuration->Windows Settings->Scripts (Logon/Logoff), refer to the below picture
group-policy.jpg
4. Double click “Logoff” to add a logoff script. Please click the “Add…” button to specify the script file to C:\Windows\System32\GroupPolicy\User\Scripts\Logoff\.  Refer to the below picture.

GP2.jpg
5. Click OK to finish the setting
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40207561
@JElster - you've chosen 3 comments as your solution, all of them do not delete subfolders in your target folder. Which of the 3 are you working with now?
0
 
LVL 1

Author Comment

by:JElster
ID: 40207694
none.. I gave up
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40207758
In that case, we should delete this question. I can do that for you if you like (or ask for Attention).
0
 
LVL 13

Expert Comment

by:Norm Dickinson
ID: 40207887
The question has been marked as solved...so dropping it and moving on would also work? Just a thought.
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

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 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