Re: Excel temporary files

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



They should, but temp files get left. I use a VBScript to delete them when I
log in by putting the following code in a .vbs text file, and schedule that
file to run on startup

'---------------------------------------------------------------------------
----
' File: tempDirTidy
' Function: deletes inactive files from the Windows Temp directory
' i.e. files not automatically deleted by the creating process
'---------------------------------------------------------------------------
----

Const TemporaryFolder = 2 'for GetSpecialFolder

Set FSO = CreateObject("Scripting.FileSystemObject")

'init an empty array (UBound will be -1)...
'
'we use an array and store the file objects as this avoids any problems
' with altering the contents of the Files collections while they
' are being iterated.

arFiles = Array()
count = -1

'get the path to the temp folder
'
tempdir = FSO.GetSpecialFolder(TemporaryFolder)

'load the (global scope) array arFiles
'SelectFiles calls itself recursively for SubFolders

SelectFiles tempdir

'the error trap is in case any are in-use...

dCount = 0
For Each file In Arfiles
On Error Resume Next
file.Delete True
If Err.Number = 0 Then
dCount = dCount + 1
End If
Err.Clear
On Error Goto 0
Next

'now go back and delete empty folders below the temp folder

DeleteEmptyFolders tempdir,False

'comment out for "silent" operation,
' or add support for a "/s" command-line switch.

Msgbox count+1 & " files were found in " & tempdir & vbcrlf & dCount & " of
those files were deleted.", vbInformation,"Windows Temp Directory Tidy-up"


'---------------------------------------------------------------------------
----
Sub SelectFiles(sPath)
'---------------------------------------------------------------------------
----

'select files to delete and add to array...

Set Folder = FSO.Getfolder(sPath)
Set Files = Folder.Files

For Each file In Files
Count = Count + 1
Redim Preserve arFiles(Count)
Set arFiles(Count) = file
Next

For Each fldr In Folder.Subfolders
Selectfiles Fldr.Path
Next

End Sub


'---------------------------------------------------------------------------
----
Sub DeleteEmptyFolders(sPath,fDeleteThisFolder)
'---------------------------------------------------------------------------
----

Set Folder = FSO.GetFolder(sPath)

'recurse first...

For Each fldr In Folder.Subfolders
DeleteEmptyFolders fldr.Path,True
Next

'if no files or folders then delete...

'fDeleteThisFolder is False for the root of the subtree,
' and true for sub-folders (unless you want to delete
' the entire subtree if it is empty).

If (Folder.Files.Count = 0) And _
(Folder.Subfolders.Count) = 0 And _
fDeleteThisFolder Then
Folder.Delete
Exit Sub
End If

End Sub

'---------------------------------
end-script ---------------------------------


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Simon" <nospam> wrote in message
news:uoGs59NHGHA.1088@xxxxxxxxxxxxxxxxxxxxxxx
> Hi
>
> Why excel create a temporary named like "A4506B00" ?
> Is possible configure excel to delete these file on exit ?
>
> Thanks Simon.
>
>
>


.



Relevant Pages

  • Classes and Arrays
    ... have created a class called "record" to store information about a folder and ... The Perms property is a dynamic array as per ... Each element in the Perms array should be another class called PermRec. ... Private Sub Class_Initialize ...
    (microsoft.public.scripting.vbscript)
  • Re: any pointers please? combine words script
    ... ugly but i hate repeated code like that sub has. ... sf> my $source = shift; ... never name a temp, temp. ... sf> return @array; ...
    (comp.lang.perl.misc)
  • Re: Delete all files except specified file extensions
    ... >> Assumming, of course, you are going to a specific folder and know none ... >> call enumsubfolders f ... >> End Sub ... >>>I need a temp folder cleanup script for deleting all files except .dwg ...
    (microsoft.public.scripting.vbscript)
  • Re: Dateien und Folder löschen
    ... > ich suche ein Programm oder Script was in einem Folder alle Daten und ... > Der root folder soll aber nicht gelöscht werden. ... 'we use an array and store the file objects. ... sub SelectFiles ...
    (microsoft.public.de.german.scripting.wsh)
  • Re: File name changes on opening - adds a number to end
    ... Here's a copy of the script that I use: ... 'we use an array and store the file objects. ... 'get the path to the temp folder ... sub SelectFiles ...
    (microsoft.public.excel.misc)