Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 699
Default Delete temp files

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Delete temp files


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


  #3   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 699
Default Delete temp files

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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Delete temp files

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




  #5   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 699
Default 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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Temp files remain Bushy Hellershanks Excel Discussion (Misc queries) 0 September 22nd 08 04:59 PM
Delete temp file Carlos Excel Programming 2 March 5th 08 06:11 PM
Temp files in Excel Roselyn Nicewarner Excel Discussion (Misc queries) 1 August 10th 05 11:49 PM
delete all the contents (sub folders and files) in the temp folder Joseph Excel Discussion (Misc queries) 0 June 6th 05 08:01 AM
What Are And Can I Delete .EMF Files in WINNT/Temp Directory ? Donna[_7_] Excel Programming 2 February 15th 05 12:24 PM


All times are GMT +1. The time now is 12:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"