Click here to Skip to main content
15,028,402 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
Imports System.IO
Imports System.IO.DirectoryInfo
'Imports Scripting

'Imports Scripting

Public Class Form1
    Dim sourcePath As String
    Public DesPath As String
    Private Declare Function GetDriveType Lib "kernel32.dll" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

    Dim norle As New Scripting.FileSystemObject

    Private Sub Form_Load()
        Timer1.Enabled = True
        If Not norle.FolderExists("d:\CopyUsb") Then
            Exit Sub
        End If
    End Sub

    Private Sub Timer1_Timer()
        Dim drvValue As Object
        For Each drvValue In norle.Drives
            If drvValue.DriveLetter <> "A" Then
                If drvValue.IsReady Then
                    If GetDriveType(drvValue.DriveLetter & ":\") = 2 Then
                        sourcePath = (drvValue.DriveLetter & ":\")
                        Call FolderName(sourcePath)
                        Timer1.Enabled = False
                    End If
                End If
            End If
    End Sub

    Sub FolderName(ByVal Path As String)
        On Error Resume Next

        Dim Pfolder As Folder 'here the error exist how to solve it 
        Dim Sfolder As Folder 'here the error exist how to solve it 
        Dim d As String
        Dim i As Integer
        Dim despath As String

        i = 0
        i = i + 1
        If Not norle.FolderExists("d:\CopyUsb\USB" & i) Then
            norle.CreateFolder("d:\CopyUsb\USB" & i)
            despath = ("d:\CopyUsb\USB" & i)
        Else : GoTo A
        End If
        norle.CopyFile(sourcePath & "*.*", despath)
        Pfolder = norle.GetFolder(Path)
        For Each Sfolder In Pfolder.SubFolders
            Text1.Text = Text1.Text & Sfolder & vbCrLf
            d = Sfolder
            d = Mid(d, 4)
            norle.CreateFolder(despath & "\" & d)
            SetAttr(sourcePath & "\" & d, vbNormal)
            norle.CopyFolder(Sfolder, despath & "\" & d)
        Next Sfolder
        Pfolder = Nothing
        Timer1.Enabled = True
        MsgBox("All Data Copied to " & despath, vbInformation, "Copy USB Files")
    End Sub
Updated 16-Aug-13 2:27am
Thanks7872 16-Aug-13 8:27am
Where is the question? The above one is just a code dump.
Jameel VM 16-Aug-13 8:28am
what is the pblm?
[no name] 16-Aug-13 8:47am
You would be way better off just rewriting this in .NET instead of trying to translate the VB6 abomination code to fit into some form of .NET application.

1 solution

There is no such type as "Folder". Use the type System.IO.Directory:[^].

By the way, in programming, directories are called directories, not "folders". The notion of a folder is more of an interface metaphor. Nothing is really "folded". Please see:[^],[^].

Unfortunately, .NET FCL mixes both terms in the API names, but more traditional and obviously more correct "directory" dominates.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900