Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove Old ( working ) + msgbox info ( not working) 1

Status
Not open for further replies.

pawelem

Technical User
Oct 8, 2015
8
DE
Code:
On Error Resume Next

Set oFileSys = WScript.CreateObject("Scripting.FileSystemObject")
sRoot = "C:\PATH"			
today = Date
nMaxFileAge = 1					

DeleteFiles(sRoot)

Function DeleteFiles(ByVal sFolder)

Set oFolder = oFileSys.GetFolder(sFolder)
Set aFiles = oFolder.Files
Set aSubFolders = oFolder.SubFolders

For Each file in aFiles
dFileCreated = FormatDateTime(file.DateCreated, "2")
If DateDiff("d", dFileCreated, today) > nMaxFileAge Then
file.Delete(True)
End If

Next

For Each folder in aSubFolders
DeleteFiles(folder.Path)
Next

End Function


Hey guys I'm trying to upgrade this script that he will be able to pop out msg box
with something like "hey we found files older than X, after clicking ok they will be deleted'


I simply modified this part:

Code:
	For Each file in aFiles
	dFileCreated = FormatDateTime(file.DateCreated, "2")
	If DateDiff("d", dFileCreated, today) > nMaxFileAge Then
        [b]objShell.Popup "Old file will be deleted after clicking ok",, "Warning"[/b]
	file.Delete(True)
	End If

but of course now I need to click on ok X times (as many files to remove)

any ideas ? ... because I'm stuck
 
If you only want the message to appear one time, you can use a boolean flag to see if you showed the message already

Code:
[highlight #FCE94F]Dim bConfirmed
bConfirmed = False[/highlight]

For Each file in aFiles
   dFileCreated = FormatDateTime(file.DateCreated, "2")
   If DateDiff("d", dFileCreated, today) > nMaxFileAge Then
      [highlight #FCE94F]If Not bConfirmed Then[/highlight]
         objShell.Popup "Old file will be deleted after clicking ok",, "Warning"
         [highlight #FCE94F]bConfirmed = True[/highlight]
      [highlight #FCE94F]End If[/highlight]
      file.Delete(True)
   End If
 
oww, your good, really good .. exactly what I needed ! Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top