Delete temp files
Thanks! I'll give it a try.
"Rick Rothstein" wrote:
This subroutine will remove **ANY** file in the specified directory whose
filename (as returned by the Dir function) does *not* have a dot in it.
Sub RemoveFilesWithNoExtensions(Directory As String)
Dim FileName As String
FileName = Dir(Directory & "\*")
Do While Len(FileName)
If InStr(FileName, ".") = 0 Then Kill Directory & "\" & FileName
FileName = Dir
Loop
End Sub
You would call it from your own function something like this...
Sub TestIt()
'
' beginning code
'
RemoveFilesWithNoExtensions "D:\Temp\TestFolder"
'
'
'
End Sub
Now, I would advise you to test the subroutine out on a copy of your
directory to make sure it works the way you want before you use it on a
directory containing real data... that is because the Kill statement that I
am using permanently deletes any files it processed (it does NOT send them
to the Recycle Bin).
--
Rick (MVP - Excel)
"Sam" wrote in message
...
The other files are the original Excel workbooks that are being saved.
They
have the ".xls" extension. I want to loop through all files in the
directory
and only delete the Types "File" as explained in my original message.
Thanks, Rick. Can this be done?
"Rick Rothstein" wrote:
You say "of a certain type"... does that mean there are other files in
the
directory that you do not want to delete? If so, do they have file
extensions on them or not?
--
Rick (MVP - Excel)
"Sam" wrote in message
...
I need a code that will delete all files in a directory that are of a
certain
type.
We have an issue with one of our servers whereby the temp files that
are
created when an ".xls" file saves are not deleted when the file saves.
They
are named: "29D41410", "31138510", etc. and do not contain file
extensions.
Properties list the Type of file as "File". Our netword amins are
stumped
but
until a solution is found, I would like to enter a code into the
Workbook
Before_Close event to loop through all files in the directory and
delete
these junk files.
Can anyone help?
Thanks,
Sam
|