Solved

DOS Batch file

Posted on 2014-07-19
8
616 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, 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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 37

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 37

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 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