Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Folder

Posted on 2008-10-10
5
Medium Priority
?
187 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
ID: 22690931
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
ID: 22690938
Sorry, that specifies 30 days, change it to
> 90
 
0
 

Author Comment

by:VBdotnet2005
ID: 22690966

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
ID: 22691047
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 2000 total points
ID: 22691069
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

971 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