Solved

VB6 filesystem object in vb2005

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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 Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

713 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