Solved

VB6 filesystem object in vb2005

Posted on 2008-10-24
3
318 Views
Last Modified: 2012-06-22
Please can someone upgrade this code from VB6 to VB 2005 as the upgrade wizard fails?


Dim Mload As Folder, RepFile As File, NewFile As String, MloadDirectory As Files
Dim FSO As FileSystemObject

Private Sub form_Load()

Set FSO = New FileSystemObject

Set Mload = FSO.GetFolder("C:\temp")
Set MloadDirectory = Mload.Files
For Each RepFile In MloadDirectory
    RepFile.Delete
Next
0
Comment
Question by:AlHal2
3 Comments
 
LVL 3

Accepted Solution

by:
Blackninja2007 earned 125 total points
ID: 22794509
imports system.io

private sub form_load()

        Dim dir As DirectoryInfo = New DirectoryInfo("C:\Temp")
        Dim files As FileInfo() = dir.GetFiles()

        For Each f As FileInfo In files
               f.delete()
        Next
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 22798249
Click on Project --> Add Reference.
Switch to the "COM" Tab.
Select the "Microsoft Scripting Runtime" Entry and Click "OK".

Your converted code:
Public Class Form1
 

    Private Mload As Scripting.Folder, RepFile As Scripting.File, NewFile As String, MloadDirectory As Scripting.Files

    Private FSO As Scripting.FileSystemObject
 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        FSO = New Scripting.FileSystemObject
 

        Mload = FSO.GetFolder("C:\temp")

        MloadDirectory = Mload.Files

        For Each RepFile In MloadDirectory

            RepFile.Delete()

        Next

    End Sub
 

End Class

Open in new window

0
 

Author Closing Comment

by:AlHal2
ID: 31509568
That's great.  Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

947 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

22 Experts available now in Live!

Get 1:1 Help Now