Computing.Net > Forums > Programming > Search & delete .tmp files but...

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Search & delete .tmp files but...

Reply to Message Icon

Name: alwaysk2
Date: October 21, 2008 at 04:23:26 Pacific
OS: Windows 2003 Ent. Server
CPU/Ram: 8 GHZ/8GB
Product: IBm
Comment:

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.tmp

it 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



Sponsored Link
Ads by Google

Response Number 1
Name: Judago
Date: October 21, 2008 at 04:38:11 Pacific
Reply:

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"


0

Response Number 2
Name: Mechanix2Go
Date: October 21, 2008 at 04:53:40 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

for /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


0

Response Number 3
Name: pball
Date: October 21, 2008 at 04:54:23 Pacific
Reply:

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!
)
pause

I 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! == ~ )


0

Response Number 4
Name: alwaysk2
Date: October 21, 2008 at 06:18:18 Pacific
Reply:

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
)
pause

I also want this batch file to delete all .tmp files in all sub directories also so will it work ?

K2™
System/Network Engineer


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Search & delete .tmp files but...

batch file to delete folders/files www.computing.net/answers/programming/batch-file-to-delete-foldersfiles/16164.html

Dos script search in .txt file P-2 www.computing.net/answers/programming/dos-script-search-in-txt-file-p2/16746.html

Delete Files Older Then x-Days www.computing.net/answers/programming/delete-files-older-then-xdays/15229.html