Solved

Folder

Posted on 2008-10-10
5
169 Views
Last Modified: 2012-05-05
How can I go in a folder and see if subfolder are created more than 90 days. If found, delete them.  

 Dim myPath As String = "mypathxyz"
        Dim myDir As New DirectoryInfo(myPath)
        Dim TimeNowx As Date = DateTime.Now

        Dim TS As TimeSpan


        For Each folder As String In Directory.GetDirectories(myPath)




        Next
0
Comment
Question by:VBdotnet2005
  • 4
5 Comments
 
LVL 11

Expert Comment

by:ladarling
Comment Utility
Something like this:
 Dim myPath As New IO.DirectoryInfo("C:\Temp")

        Dim subFolders = myPath.GetDirectories()

        For Each folder In subFolders

            Dim ts As TimeSpan = folder.CreationTime.Subtract(Now)

            If ts.Days > 30 Then

                My.Computer.FileSystem.DeleteDirectory(folder.FullName, FileIO.DeleteDirectoryOption.DeleteAllContents)

            End If

        Next

Open in new window

0
 
LVL 11

Expert Comment

by:ladarling
Comment Utility
Sorry, that specifies 30 days, change it to
> 90
 
0
 

Author Comment

by:VBdotnet2005
Comment Utility

You don't have to declare "folder"  > For Each folder In subFolders

also  Dim subFolders = myPath.GetDirectories()   > what would Subfolders data type be? string????
0
 
LVL 11

Expert Comment

by:ladarling
Comment Utility
Sorry for the confusion, I use the type inferrence feature in both lines...
-SubFolders is inferred to be a collection of DirectoryInfo() class
-folder is inferred to be a single DirectoryInfo() class
0
 
LVL 11

Accepted Solution

by:
ladarling earned 500 total points
Comment Utility
So, this is fully qualified types..

Dim myPath As New IO.DirectoryInfo("C:\Temp")
Dim subFolders() As IO.DirectoryInfo = myPath.GetDirectories()
For Each folder As IO.DirectoryInfo In subFolders
Dim ts As TimeSpan = folder.CreationTime.Subtract(Now)
If ts.Days > 30 Then
My.Computer.FileSystem.DeleteDirectory(folder.FullName, FileIO.DeleteDirectoryOption.DeleteAllContents)
End If
Next
 
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now