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
Solved

Folder

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net - Get ColumnNames of SQL Table 4 15
Get distinct values from excel or comm seperated file 4 30
Help with error in Query 2 31
run a stored procedure from vb.net 1 27
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…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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