Solved

DOS Batch file

Posted on 2014-07-19
8
608 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

862 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

23 Experts available now in Live!

Get 1:1 Help Now