Solved

DOS Batch file

Posted on 2014-07-19
8
600 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 37

Expert Comment

by:Gerwin Jansen
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
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 37

Expert Comment

by:Gerwin Jansen
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 37

Expert Comment

by:Gerwin Jansen
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

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

18 Experts available now in Live!

Get 1:1 Help Now