Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Need a function to delete files in a specified fol...
Author:
Ralf Koch
E-mail:
Click to e-mail author
Website:
http://www.kotech-enterprises.com
Submitted:
5/17/2002
Version:
VB6, VB.NET
Compatibility:
VB6, VB.NET
Category:
File Manipulation
Views:
15996
Need a function to delete files in a specified folder which are older than x days? This code snippet does just that! You can call the code with a timer so you have an automated directory scanner.
Declarations:
'none
Code:
Public Function delOldFiles(delDays as integer, scanDir as string) '
'-----------------------------------------------------' Project : XMLSentinel ' Procedure : delOldFiles ' Description: DELETE OLD FILES ' Created by : Project Administrator ' Date-Time : 5/16/2002-4:26:37 PM ' Parameters : delDays -> number of days ' scanDir -> the directory '-----------------------------------------------------'
Dim fs As Object On Error GoTo errorHandler Set fs = CreateObject("Scripting.FileSystemObject") ' CHECK IF THE DIRECTORY EXISTS If Dir$(scanDir, vbDirectory) <> "" Then ' DIRECTORY DOES EXIST, SO GO ON ... Dim fileDate As Date ' Declare variables. Dim f, f1, fc Set f = fs.GetFolder(scanDir) Set fc = f.Files For Each f1 In fc fileDate = f1.DateCreated If DateDiff("d", fileDate, Now) > delDays Then f1.Delete End If Next End If Set fs = Nothing Exit Function errorHandler: Resume Next End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement