Solved

VB6 filesystem object in vb2005

Posted on 2008-10-24
3
327 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
[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
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 86

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

710 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