Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
we are making a batch file for our server's specific location which contains lots of .tmp files and ~*.tmp files what we need to make is a batch file which will delete all the .tmp files but it will not delete ~*.tmp files.
like if the folder has below stated files
test.tmp
~hello.tmpit will only delete test.tmp not the ~hello.tmp in same folder. any ideas... how to search on it and delete the specified extension file.
K2™
System/Network Engineer

Give this a run and see if it echo the files you want deleted.
for /f "delims=" %%g in ('dir *.tmp /b /a-d^|findstr /v /b ~') do echo del "%%~fg"

@echo off
setLocal EnableDelayedExpansionfor /f "tokens=* delims= " %%a in ('dir/b/s/a-d *.tmp') do (
set str=%%~Na
if not "!str:~0,1!"=="~" echo del %%a
)
=====================================
If at first you don't succeed, you're about average.M2

This isn't that hard.
@echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%x in ('dir /b *.tmp') do (
set var=%%x
set hey=!var:~0,1!
if not !hey! == ~ echo del !var!
)
pauseI have an echo instead the command to delete. I would test the script to be sure it works right. It should just say del (file name). When you confirm it works just remove the echo from "echo del !var!" then it will delete them.
(side note, I had to use two variables since it didn't like !var:~0,1! == ~ )

hi Mechanix2Go bro your solutions are also doing the same.
Mechanix2Go its just deleted 3 files not every .tmp files I don't know whats wrong with it as I just edited it like this :
@echo off
setlocal enabledelayedexpansion
set a="c:\temp"for /f "tokens=* delims= " %%a in ('dir/b/s/a-d %a%\*.tmp') do (
set str=%%~Na
if not "!str:~0,1!"=="~" del %%a
)
pauseI also want this batch file to delete all .tmp files in all sub directories also so will it work ?
K2™
System/Network Engineer

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |