Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Help with deleting all files inside of a folder from Excel?

Hey,

As per my message below (the screen you were just at before you came
in here), is there a way to make Excel run a macro to delete any files
located inside of the Windows Temp Folder? Thanks!!!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Help with deleting all files inside of a folder from Excel?

Look into using Kill.

NickHK

wrote in message
ups.com...
Hey,

As per my message below (the screen you were just at before you came
in here), is there a way to make Excel run a macro to delete any files
located inside of the Windows Temp Folder? Thanks!!!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Help with deleting all files inside of a folder from Excel?

Here's a little VBScript that I use to clear temporary files. I use it as a
scheduled job which runs when I logon, but it should easily convert to VBA
as long as you have FSO.


If you have an y problems converting it, give us a shout, and I will give it
a go.


'---------------------------------------------------------------------------
' 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

(replace somewhere in email address with gmail if mailing direct)

wrote in message
ups.com...
Hey,

As per my message below (the screen you were just at before you came
in here), is there a way to make Excel run a macro to delete any files
located inside of the Windows Temp Folder? Thanks!!!



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
search folder/directory for a phrase inside excel files pwrichcreek Excel Discussion (Misc queries) 5 August 11th 08 09:39 PM
I would like to print the titles of files inside a folder. onenevadadollar Excel Worksheet Functions 1 November 17th 05 12:26 AM
DELETING FILES FROM A FOLDER WITH SPECIFIC EXTENSION R v Deursen Excel Programming 1 May 28th 04 02:36 PM
rename folder o files with value from inside each wbk Max Bialystock Excel Programming 2 January 2nd 04 09:24 AM
Deleting Files in Folder JEFFRO Excel Programming 5 December 14th 03 12:12 AM


All times are GMT +1. The time now is 03:03 AM.

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"