Hi,
I Need some help with writing code to get the Names of folders that sit in a specific Drive location.
I know from previous information provided on here that a Loop is required, but I don't know how to get a folder name:
The folder names are in 6 digit date format without the slashes for instance today date 24/05/2010 is shown as the folder name like this 240510.
Below is the code I have written so far with help from this forum, but I'm stuck on how to get the folder name
============
BEGIN CODE
============
Dim FS As FileSystemObject ' Declares the File System Object
Dim Folder As Folder 'Declares the Folder Object
Dim ImagePath 'Declares the ImagePath variable
Dim subFolder As Folder
Dim dtmDate As Date
Dim DateFormat As String
'Set the image path here [the location where images are be stored]
ImagePath = "\\prdfs01\images\"
'Set the File System Object
Set FS = New FileSystemObject
Set Folder = FS.GetFolder(ImagePath)
'Get the current date - 6 months
'Loops through the subfolders
For Each subFolder In Folder.Folders
'In here I believe I need some code that will get each folders name in turn, I will write additional code here also to turn the folder name in to a real date format and the If statement below will then do the rest
'If the folder name [date] is equal to or less then the current date - 6 months
If subFolder.Name <= Format(DateFormat, "yyyymmdd") Then
'Delete the folder
subFolder.Delete True
End If
DoEvents
'Indicates in the progress bar the folder being worked on
DoCmd.Echo True, "Deleting Historic Image Folders :" & Folder & " " & subFolder
Next
============
END CODE
============
Any assistance would be most appreciated.
John
I Need some help with writing code to get the Names of folders that sit in a specific Drive location.
I know from previous information provided on here that a Loop is required, but I don't know how to get a folder name:
The folder names are in 6 digit date format without the slashes for instance today date 24/05/2010 is shown as the folder name like this 240510.
Below is the code I have written so far with help from this forum, but I'm stuck on how to get the folder name
============
BEGIN CODE
============
Dim FS As FileSystemObject ' Declares the File System Object
Dim Folder As Folder 'Declares the Folder Object
Dim ImagePath 'Declares the ImagePath variable
Dim subFolder As Folder
Dim dtmDate As Date
Dim DateFormat As String
'Set the image path here [the location where images are be stored]
ImagePath = "\\prdfs01\images\"
'Set the File System Object
Set FS = New FileSystemObject
Set Folder = FS.GetFolder(ImagePath)
'Get the current date - 6 months
'Loops through the subfolders
For Each subFolder In Folder.Folders
'In here I believe I need some code that will get each folders name in turn, I will write additional code here also to turn the folder name in to a real date format and the If statement below will then do the rest
'If the folder name [date] is equal to or less then the current date - 6 months
If subFolder.Name <= Format(DateFormat, "yyyymmdd") Then
'Delete the folder
subFolder.Delete True
End If
DoEvents
'Indicates in the progress bar the folder being worked on
DoCmd.Echo True, "Deleting Historic Image Folders :" & Folder & " " & subFolder
Next
============
END CODE
============
Any assistance would be most appreciated.
John