Function ChkCreateFolder(ipicpath As String)
    Dim fso As New Scripting.FileSystemObject
    Dim nFolder As Folder
    Dim nFolderPath As String
    nFolderPath = fso.GetParentFolderName(ipicpath)
    
    If Not fso.FolderExists(nFolderPath) Then
        If Not fso.FolderExists(fso.GetParentFolderName(nFolderPath)) Then
            ChkCreateFolder fso.GetParentFolderName(nFolderPath)
        Else
            fso.CreateFolder nFolderPath
        End If
    End If
End Function看看哪里有问题 ????

解决方案 »

  1.   

    Function ChkCreateFolder(ipicpath As String)
        Dim fso As New Scripting.FileSystemObject
        Dim nFolderPath As String
        nFolderPath = fso.GetParentFolderName(ipicpath)
        If Not fso.FolderExists(nFolderPath) Then
            ChkCreateFolder nFolderPath
        Else
            fso.CreateFolder ipicpath
        End If
    End Function
      

  2.   

    不行啊。当ipicpath = "G:\datastore\photouse\smallPic\PhotoR11\2004100811\20041008m4f4c5i5e_1.jpg"时,递归到G:\datastore\photouse\smallPic后就退出了,
    递归的条件和递归执行部分有什么问题?
      

  3.   

    刚才没有仔细看, 是有问题。
    现在测试过了, 应该是这样的:
    Sub ChkCreateFolder(ipicpath As String)
        Dim fso As New Scripting.FileSystemObject
        Dim nFolderPath As String
        nFolderPath = fso.GetParentFolderName(ipicpath)
        If Not fso.FolderExists(nFolderPath) Then
            ChkCreateFolder nFolderPath
        End If
        fso.CreateFolder ipicpath
    End Sub
      

  4.   

    另外,ipicpath = "G:\datastore\photouse\smallPic\PhotoR11\2004100811\20041008m4f4c5i5e_1.jpg"作为参数来调用这个函数会有问题, 应该先让ipicpath = "G:\datastore\photouse\smallPic\PhotoR11\2004100811",然后再调用。
      

  5.   

    你已经不存在了,else一执行你就创建不了了,所以要跳出判断语句来
      

  6.   

    好麻烦,为什么不用现成的控件?COMMONDIALOG、DIR、FILE,或者还可以用API
      

  7.   

    但我的参数是ipicpath = "G:\datastore\photouse\smallPic\PhotoR11\2004100811\20041008m4f4c5i5e_1.jpg"就没有办法了么?
      

  8.   

    nFolderPath = fso.GetParentFolderName(ipicpath)
    If Not fso.FolderExists(nFolderPath) Then
            If Not fso.FolderExists(fso.GetParentFolderName(nFolderPath)) Then
    就是把后面的文件名去掉啊
      

  9.   


    nFolderPath = fso.GetParentFolderName(ipicpath)
    If Not fso.FolderExists(nFolderPath) Then
            If Not fso.FolderExists(fso.GetParentFolderName(nFolderPath)) Then你不能在递过函数中做这个啊! 把这个放在递归函数的调用之前去做,也就是说不能在ChkCreateFolder函数中出现以上语句。
      

  10.   

    为了达到目的,只有分成两个函数写了。
    Function ChkCreateFolder(ipicpath As String)
        Dim fso As New Scripting.FileSystemObject
        Dim nFolder As Folder
        Dim nFolderPath As String
        nFolderPath = fso.GetParentFolderName(ipicpath)
        inChkCreateFolder nFolerPath
    End Function
       function inChkCreateFolder(ipath As String)
        Dim fso2 As New Scripting.FileSystemObject
        Dim nFolderPath2 As String
        nFolderPath2 = fso2.GetParentFolderName(ipath)
        If Not fso2.FolderExists(nFolderPath2) Then
            inChkCreateFolder nFolderPath2
        End If
        fso2.CreateFolder ipath
    End function呵呵