Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch file to perform start, run, %TEMP% and delete all

Tags:

batch-file

looking for a way to perform the following:

Start > Run > "%TEMP% > Delete everything (skipping any conflicts).

so Far I have

@echo off
start %TEMP%
DEL *.*

I suppose I could use CD to get to the folder, the thing I'm wondering is if there are any instances where it cannot delete an a dialog box comes up, I want to skip these.

Thanks for the help! Liam

like image 364
Liam Coates Avatar asked May 23 '12 09:05

Liam Coates


People also ask

How do I get a batch file to run on startup for all users?

Press Start, type Run, and press Enter . In the Run window, type shell:startup to open the Startup folder. Once the Startup folder is opened, click the Home tab at the top of the folder. Then, select Paste to paste the shortcut file into the Startup folder.

What does %1 mean in a batch file?

When used in a command line, script, or batch file, %1 is used to represent a variable or matched string. For example, in a Microsoft batch file, %1 can print what is entered after the batch file name.


2 Answers

The following batch commands are used to delete all your temp, recent and prefetch files on your System.

Save the following code as "Clear.bat" on your local system

*********START CODE************

@ECHO OFF

del /s /f /q %userprofile%\Recent\*.*

del /s /f /q C:\Windows\Prefetch\*.*

del /s /f /q C:\Windows\Temp\*.*

del /s /f /q %USERPROFILE%\appdata\local\temp\*.*


/Below command to Show the folder after deleted files

Explorer %userprofile%\Recent

Explorer C:\Windows\Prefetch

Explorer C:\Windows\Temp

Explorer %USERPROFILE%\appdata\local\temp


*********END CODE************
like image 115
Ramanan K Avatar answered Sep 19 '22 10:09

Ramanan K


del won't trigger any dialogs or message boxes. You have a few problems, though:

  1. start will just open Explorer which would be useless. You need cd to change the working directory of your batch file (the /D is there so it also works when run from a different drive):

    cd /D %temp%
    
  2. You may want to delete directories as well:

    for /d %%D in (*) do rd /s /q "%%D"
    
  3. You need to skip the question for del and remove read-only files too:

    del /f /q *
    

so you arrive at:

@echo off
cd /D %temp%
for /d %%D in (*) do rd /s /q "%%D"
del /f /q *
like image 29
Joey Avatar answered Sep 19 '22 10:09

Joey