Creating a .bat file?

K

Kate

XP Home SP3
Apologies if this is not the place to ask this question, but I would
like to create a .bat file or something to delete the dozens of temp
files which a program I have leaves in my Temp folder every time I run
it. The files are always named in a particular way so can easily be
identified, I think/hope. I do not want to delete all of the files in
the Temp folder, though. Is this possible, please, and how would I go
about it?

Many thanks
Kate
 
L

Leonard Grey

Without knowing what program you're talking about, what kind of
temporary files it creates and why, it's impossible to advise you on the
wisdom of deleting these files.

But if you're bound and determined to get rid of them, try the Disk
Cleanup Wizard in Windows, or one of the millions of programs available
for download that do this. (CCleaner is often mentioned here.)
 
K

Kate

Thanks for the reply.
I would like to be able to just click, say, a shortcut after I had run
the program, rather than open another program to "search and destroy".
I might as well open the Temp folder and delete them manually,
otherwise. The files are created by Pace Interlok and are totally
unnecessary to the subsequent running of the program. Indeed, each
time the program is opened, yet another load of files are saved rather
than it using the existing ones and they can multiply to such an
extent that they number in their 100s if I don`t clear up each time.
The program that uses Interlok is DxO Optics, a very good RAW
converter, and it is a pity that they use such intrusive anti-piracy
software.
Thanks again
Kate
 
L

Leonard Grey

I clean out temp files (with CCleaner) in two clicks. If you can stomach
one extra click, you don't need to learn about batch files or take the
risk of making a mistake.
 
J

John John - MVP

Kate said:
XP Home SP3
Apologies if this is not the place to ask this question, but I would
like to create a .bat file or something to delete the dozens of temp
files which a program I have leaves in my Temp folder every time I run
it. The files are always named in a particular way so can easily be
identified, I think/hope. I do not want to delete all of the files in
the Temp folder, though. Is this possible, please, and how would I go
about it?

Trying something like this at the command prompt should give you ideas:

for %f in (c:\"Temp Folder Name"\*.tmp) do @echo %f

The above is perfectly safe, it will only echo file names. To delete
files replace the @echo command with del and surround the variable with
quotation marks, the quotation marks are needed if the filenames
contains spaces. At the Command Prompt use single %, in a batch file
double them up:

for %%f in (c:\"Temp Folder Name"\*.tmp) do del "%%f"

Careful!!! files deleted by batch file or at the Command Prompt do not
go to the Recycle Bin!

John
 
K

Kate

Does CCleaner clear the entire Temp folder, or can I specify which
files I want deleted, please? Incidentally, I thought that temp files
were just that : temporary, and could be deleted with impunity unless
a program was actually running and using them.

Kate
 
B

Bill in Co.

Kate said:
XP Home SP3
Apologies if this is not the place to ask this question, but I would
like to create a .bat file or something to delete the dozens of temp
files which a program I have leaves in my Temp folder every time I run
it. The files are always named in a particular way so can easily be
identified, I think/hope. I do not want to delete all of the files in
the Temp folder, though. Is this possible, please, and how would I go
about it?

Many thanks
Kate

The syntax for doing something like that is like this:
del \windows\temp\trb*.tmp
(In this example we'd be referring to the \windows\temp folder).

This would delete all .tmp files in that folder beginning with trb
You simply put that line above into a text file created with Notepad, and
rename that text file with a .bat extension. You could call it
erasetmp.bat.
 
K

Ken Blake, MVP

Incidentally, I thought that temp files
were just that : temporary,


Yes, exactly. However, every now and then they get left behind,
usually because the program that created them doesn't close normally.

and could be deleted with impunity unless
a program was actually running and using them.


Yes, however you can always delete (at least try to delete) them with
impunity. You won't be permitted to delete one if a running program is
using it.
 
L

Leonard Grey

Ccleaner cleans the Windows temporary folder and you can specify
additional folders to clean out.

Temporary files cannot be cleaned out 'with impunity'. Sometimes they
hold information a program needs, albeit temporarily.

I'm not making some kind of product endorsement for CCleaner. My point
is, why re-invent the wheel?
 
K

Kate

Bill in Co. said:
The syntax for doing something like that is like this:
del \windows\temp\trb*.tmp
(In this example we'd be referring to the \windows\temp folder).

This would delete all .tmp files in that folder beginning with trb
You simply put that line above into a text file created with
Notepad, and rename that text file with a .bat extension. You could
call it erasetmp.bat.
Might this work, do you think?
del\Documents and Settings\(user name)\Local Settings\Temp\PTM***.tmp
del\Documents and Settings\(user name)\Local Settings\Temp\t*****.tmp

The .tmp files always have numbers and/or letters after the PTM or t
so I have used asterisks as wild-cards. Perhaps more importantly, if
it doesn`t work, can an incorrectly executed .bat file cause problems
elsewhere, do you know?

Thanks to everyone who replied
Kate
 
B

Bill Sharpe

Kate said:
Might this work, do you think?
del\Documents and Settings\(user name)\Local Settings\Temp\PTM***.tmp
del\Documents and Settings\(user name)\Local Settings\Temp\t*****.tmp

The .tmp files always have numbers and/or letters after the PTM or t so
I have used asterisks as wild-cards. Perhaps more importantly, if it
doesn`t work, can an incorrectly executed .bat file cause problems
elsewhere, do you know?

Thanks to everyone who replied
Kate

These should work, but leave a space after "del". Also, you only need
one asterisk, not multiple asterisks in these commands.

Bill
 
K

Ken Blake, MVP

Might this work, do you think?
del\Documents and Settings\(user name)\Local Settings\Temp\PTM***.tmp
del\Documents and Settings\(user name)\Local Settings\Temp\t*****.tmp


Note that there needs to be a space after the del.

The .tmp files always have numbers and/or letters after the PTM or t
so I have used asterisks as wild-cards. Perhaps more importantly, if
it doesn`t work, can an incorrectly executed .bat file cause problems
elsewhere, do you know?


An asterisk means some number of characters and you can't use multiple
asterisks that way. Use a question mark as wildcard for a single
character.

But why do you want to specify what files you want to delete? Just
delete all the files in the temp folder. Personally I think the
easiest way to do that is to go to the temp folder in Windows
Explorer, sort all the files by date with the oldest on top, select
them all with Ctrl-A, then press the delete key to delete them all. It
will delete everything until it gets to the newest ones that are still
being used.
 
B

Bill in Co.

Note that there needs to be a space after the del.




An asterisk means some number of characters and you can't use multiple
asterisks that way. Use a question mark as wildcard for a single
character.

But why do you want to specify what files you want to delete? Just
delete all the files in the temp folder.

I wouldn't do that, for a couple of reasons. One is for the history
(sometimes I'm chasing down some bugs or mods, and it's helpful to see what
was left or created in there), and the other reason is that sometimes some
temp files are there as part of a program install or uninstall (although
they might be locked, in which case it's not an issue, admitedly). So my
feeling is, why not just delete the undesired ones, and perhaps even know or
be able to determine what app is creating them in the process.
 
B

Bill in Co.

Kate said:
Might this work, do you think?
del\Documents and Settings\(user name)\Local Settings\Temp\PTM***.tmp
del\Documents and Settings\(user name)\Local Settings\Temp\t*****.tmp

As already mentioned, you need to add a space after del command.
Also, make it t*.tmp in the batch file (just one asterisk is allowed).
An alternate command would be t?????.tmp, but that's not needed here, but
that would specifically ONLY delete filenames (with t, followed by 5
alphanumeric prefixes). The * is more global: t*.tmp will delete any
filename ending in .tmp that starts with the letter t.
The .tmp files always have numbers and/or letters after the PTM or t
so I have used asterisks as wild-cards. Perhaps more importantly, if
it doesn`t work, can an incorrectly executed .bat file cause problems
elsewhere, do you know?

Well, if you really messed it up, you could delete some other files you
hadn't intended if they matched the conditions specified in the batch file,
which seems unlikely.
 
K

Kate

Bill in Co. said:
As already mentioned, you need to add a space after del command.
Also, make it t*.tmp in the batch file (just one asterisk is
allowed).
An alternate command would be t?????.tmp, but that's not needed
here, but that would specifically ONLY delete filenames (with t,
followed by 5 alphanumeric prefixes). The * is more global:
t*.tmp will delete any filename ending in .tmp that starts with the
letter t.

Does that mean the * can be letters and/or numbers, and is a .bat file
case-sensitive? I have some TWAIN and Twunk files in my Temp folder
and although it doesn`t really matter if they are deleted as they are
re-created when I next use my scanner, it would be more...elegant...
if the instructions could be targetted at just the Interlok files.
Well, if you really messed it up, you could delete some other files
you hadn't intended if they matched the conditions specified in the
batch file, which seems unlikely.

I know these files are useless after the program is closed as I have
been manually deleting them without ill-effects after each closure.
Most of the other files in my Local Settings/Temp folder are things
which just get re-created if I do delete them (see above), so I tend
to leave them alone. I think I will give the .bat file a try and see
how it goes. I suspect that if it works well, there will be quite a
few DxO Optics users celebrating, as it isn`t just me that finds these
Interlok files a PITA.

Thanks again to all.
Kate
 
K

Kate

Kate said:
Does that mean the * can be letters and/or numbers, and is a .bat
file
case-sensitive? I have some TWAIN and Twunk files in my Temp folder
and although it doesn`t really matter if they are deleted as they
are
re-created when I next use my scanner, it would be more...elegant...
if the instructions could be targetted at just the Interlok files.


I know these files are useless after the program is closed as I have
been manually deleting them without ill-effects after each closure.
Most of the other files in my Local Settings/Temp folder are things
which just get re-created if I do delete them (see above), so I tend
to leave them alone. I think I will give the .bat file a try and
see
how it goes. I suspect that if it works well, there will be quite a
few DxO Optics users celebrating, as it isn`t just me that finds
these
Interlok files a PITA.

Thanks again to all.
Kate

It didn`t work. In fact, nothing beginning with a P or t (or even a p
or a T!) is being deleted, although I have checked the wording most
carefully and it all seems to be correct. Oh well, it looks like I
shall have to manually delete them after all. Disappointing.

Kate
 
B

Bill in Co.

Kate said:
Does that mean the * can be letters and/or numbers,

* covers letters or numbers (any alpha-numeric characters) - it's a generic
global parameter.
 
B

Bill in Co.

Yes (as mentioned - it's a global substitute)

No.

I have some TWAIN and Twunk files in my Temp folder
It didn`t work. In fact, nothing beginning with a P or t (or even a p
or a T!) is being deleted, although I have checked the wording most
carefully and it all seems to be correct. Oh well, it looks like I
shall have to manually delete them after all. Disappointing.

Kate

I'm not sure exactly what the contents of your "erasetmp.bat" file looks
like. Maybe you can copy and paste it into here. The punctuation is
critical, of course. I assume you created a pure text file in *Notepad*.
Don't use a word processor for this - it needs to be a pure text file.

Here again is a simple one:

del c:\windows\*.tmp (note: space only after the del command)

would delete all .tmp files in that directory (after just double clicking on
the "erasetmp.bat" file it's written in).
 
J

John John - MVP

Kate said:
It didn`t work. In fact, nothing beginning with a P or t (or even a p
or a T!) is being deleted, although I have checked the wording most
carefully and it all seems to be correct. Oh well, it looks like I
shall have to manually delete them after all. Disappointing.

It should work, I think that you're doing something wrong. Experiment
with it at the Command Prompt using the DIR command and see what the
command returns:

dir /b c:\"folder name\p*.tmp"

If the DIR command returns a proper list of files that you want to
delete then then there is no reason why the DEL command shouldn't delete
them. Remember that if there are spaces in the path or file names that
you *must* encapsulate the path with "quotation marks" (as above) or
else the command will fail.

John
 
K

Kate

John John - MVP said:
It should work, I think that you're doing something wrong.
Experiment with it at the Command Prompt using the DIR command and
see what the command returns:

dir /b c:\"folder name\p*.tmp"

If the DIR command returns a proper list of files that you want to
delete then then there is no reason why the DEL command shouldn't
delete them. Remember that if there are spaces in the path or file
names that you *must* encapsulate the path with "quotation marks"
(as above) or else the command will fail.

John

The command prompt worked correctly, so I must be doing something
wrong creating the .bat. In Notepad, I wrote
del \F:\Documents and Settings\(user name)\Local Settings\Temp\p*.tmp
del \F:\Documents and Settings\(user name)\Local Settings\Temp\t*.tmp

(F: is my main drive, BTW, as you probably guessed and I am copying
the path exactly as it appears in the address bar of my Temp folder)

I have tried it with and without F:, with quotation marks and without
(grasping at straws there), but it still doesn`t work. I also tried
replacing the * with ????, targetting specific files, but to no avail.
Then I thought that maybe these Interlok files are locked in some way,
so I tried naming a specific log file which has nothing to do with
Interlok, but that didn`t erase either. I cannot see where I am going
wrong!

Thanks
Kate
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top