?
Solved

DOS Batch file

Posted on 2014-07-19
8
Medium Priority
?
638 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
[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
8 Comments
 
LVL 7

Accepted Solution

by:
Raghu Mutalikdesai earned 800 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 600 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 2

Assisted Solution

by:Parrish Chamberlain
Parrish Chamberlain earned 300 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month8 days, 6 hours left to enroll

764 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