Solved

VB6 filesystem object in vb2005

Posted on 2008-10-24
3
315 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

19 Experts available now in Live!

Get 1:1 Help Now