vb6到vb.net但声明文件夹时出错 [英] vb6 to vb.net but error in declaring folders

查看:65
本文介绍了vb6到vb.net但声明文件夹时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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
            norle.CreateFolder("d:\CopyUsb")
        Else
            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
        Next
    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
A:
        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

推荐答案

没有类似文件夹。使用类型 System.IO.Directory

http://msdn.microsoft.com/en-us/library/system.io.directory.aspx [ ^ ]。



顺便说一句,在编程中,目录称为目录,而不是文件夹。文件夹的概念更多是界面隐喻。什么都没有真正折叠。请参阅:

http://en.wikipedia.org/wiki/Metaphor [< a href =http://en.wikipedia.org/wiki/Metaphortarget =_ blanktitle =New Window> ^ ],

http://en.wikipedia.org/wiki/Interface_metaphor [ ^ ]。



不幸的是,.NET FCL混合了API名称中的两个术语,但更传统,更明显更正确的目录占主导地位。



-SA
There is no such type as "Folder". Use the type System.IO.Directory:
http://msdn.microsoft.com/en-us/library/system.io.directory.aspx[^].

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:
http://en.wikipedia.org/wiki/Metaphor[^],
http://en.wikipedia.org/wiki/Interface_metaphor[^].

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

—SA


这篇关于vb6到vb.net但声明文件夹时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆