Hi,
I've learnt how to delete folders and my process works fine, however I now have an additional task of having to delete text files that are contained within folders. However it's not just as simply as deleting anything with a ".txt" extension. I need to only delete those text files whose date is greater than 6 months. The date is contained within the text file name as follows:
aeg_130109.txt
beko_140209.txt
bosch_121208.txt
and so on.
These files reside in their own folders as follows:
aeg.fof
beko.fof
bosch.fof
and these folders reside in a top level folder called "BackupProdRegOnprdfs01\aeg.fof", which in turn sits on a network drive, so the full path for instance to the aeg.fof would be:
\\Leint03\ocrff_test\BackupProdRegOnprdfs01\aeg.fof
Leint03\ocrff_test is the server
BackupProdRegOnprdfs01 is the top level folder
aeg.fof is the folder in which the text files reside
So I need to have code that identifies the date part of the text file name and if it is greater than 6 months, then delete that text file and for this to automatically go to each ".fof" folder in turn and delete any text files that are older than 6 months. I have written the following code, but have got struck on how to get to the date part of the text file name.
================
BEGIN CODE
================
Dim FSO As FileSystemObject ' Declares the File System Object
Dim Folder As Folder 'Declares the Folder Object
Dim TextFilePathAEG 'Declares the TextFilePathAEG variable
Dim SubFolder As Folder
Dim File As File
Dim dtmDate As Date
Dim TextFileDate
'Set the text file paths here [the location where the text files are be stored]
TextFilePathAEG = "\\Leint03\ocrff_test\BackupProdRegOnprdfs01\aeg.fof"
Set FSO = New FileSystemObject
' If we can't read the images folder, stop running
If Not FSO.FolderExists(TextFilePathAEG) Then
MsgBox "Folder Doesn't Exist"
End
End If
For Each File In Folder.Files
' If file is a txt file then Delete it
If Right(File.Name, 4) = ".txt" Then
End If
Next
================
END CODE
================
Your assistance would be most appreciated.
John
I've learnt how to delete folders and my process works fine, however I now have an additional task of having to delete text files that are contained within folders. However it's not just as simply as deleting anything with a ".txt" extension. I need to only delete those text files whose date is greater than 6 months. The date is contained within the text file name as follows:
aeg_130109.txt
beko_140209.txt
bosch_121208.txt
and so on.
These files reside in their own folders as follows:
aeg.fof
beko.fof
bosch.fof
and these folders reside in a top level folder called "BackupProdRegOnprdfs01\aeg.fof", which in turn sits on a network drive, so the full path for instance to the aeg.fof would be:
\\Leint03\ocrff_test\BackupProdRegOnprdfs01\aeg.fof
Leint03\ocrff_test is the server
BackupProdRegOnprdfs01 is the top level folder
aeg.fof is the folder in which the text files reside
So I need to have code that identifies the date part of the text file name and if it is greater than 6 months, then delete that text file and for this to automatically go to each ".fof" folder in turn and delete any text files that are older than 6 months. I have written the following code, but have got struck on how to get to the date part of the text file name.
================
BEGIN CODE
================
Dim FSO As FileSystemObject ' Declares the File System Object
Dim Folder As Folder 'Declares the Folder Object
Dim TextFilePathAEG 'Declares the TextFilePathAEG variable
Dim SubFolder As Folder
Dim File As File
Dim dtmDate As Date
Dim TextFileDate
'Set the text file paths here [the location where the text files are be stored]
TextFilePathAEG = "\\Leint03\ocrff_test\BackupProdRegOnprdfs01\aeg.fof"
Set FSO = New FileSystemObject
' If we can't read the images folder, stop running
If Not FSO.FolderExists(TextFilePathAEG) Then
MsgBox "Folder Doesn't Exist"
End
End If
For Each File In Folder.Files
' If file is a txt file then Delete it
If Right(File.Name, 4) = ".txt" Then
End If
Next
================
END CODE
================
Your assistance would be most appreciated.
John