×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)

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
        objShell.Popup "Old file will be deleted after clicking ok",, "Warning"
	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

RE: Remove Old ( working ) + msgbox info ( not working)

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

Dim bConfirmed
bConfirmed = False

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

RE: Remove Old ( working ) + msgbox info ( not working)

(OP)
oww, your good, really good .. exactly what I needed ! Thanks

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close