Solved

Folder

Posted on 2008-10-10
5
180 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 500 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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