PC Review


Reply
Thread Tools Rate Thread

Delete temp files

 
 
Sam
Guest
Posts: n/a
 
      10th Jul 2009
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 With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      10th Jul 2009

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" <(E-Mail Removed)> wrote in message
news:B4907DBE-340D-4F79-83E3-(E-Mail Removed)...
>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 With Quote
 
Sam
Guest
Posts: n/a
 
      10th Jul 2009
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" <(E-Mail Removed)> wrote in message
> news:B4907DBE-340D-4F79-83E3-(E-Mail Removed)...
> >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 With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      10th Jul 2009
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" <(E-Mail Removed)> wrote in message
news:66F459A4-F313-41A1-AE85-(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
>> news:B4907DBE-340D-4F79-83E3-(E-Mail Removed)...
>> >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 With Quote
 
Sam
Guest
Posts: n/a
 
      10th Jul 2009
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" <(E-Mail Removed)> wrote in message
> news:66F459A4-F313-41A1-AE85-(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> >> news:B4907DBE-340D-4F79-83E3-(E-Mail Removed)...
> >> >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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to delete temp.files =?Utf-8?B?QWx2aW4=?= Microsoft Word Document Management 0 29th Jan 2006 10:39 AM
Can't Delete Temp\Temporary Internet Files\ Files Larry R Harrison Jr Windows XP Internet Explorer 4 8th Feb 2005 04:32 PM
Delete Temp files? Paul Long Windows XP Help 0 25th May 2004 04:32 PM
Index.dat Suite - View & Delete Index.dat Files, Temp Internet Files (TIF), Cookies, History, Temp Files BillR Freeware 39 1st Nov 2003 09:40 PM
Can't delete temp files for CD-Rom Chris Windows XP Performance 0 7th Aug 2003 02:28 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:09 PM.