Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Folder

Posted on 2008-10-10
5
Medium Priority
?
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

722 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