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看看哪里有问题 ????
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看看哪里有问题 ????
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
递归的条件和递归执行部分有什么问题?
现在测试过了, 应该是这样的:
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
If Not fso.FolderExists(nFolderPath) Then
If Not fso.FolderExists(fso.GetParentFolderName(nFolderPath)) Then
就是把后面的文件名去掉啊
nFolderPath = fso.GetParentFolderName(ipicpath)
If Not fso.FolderExists(nFolderPath) Then
If Not fso.FolderExists(fso.GetParentFolderName(nFolderPath)) Then你不能在递过函数中做这个啊! 把这个放在递归函数的调用之前去做,也就是说不能在ChkCreateFolder函数中出现以上语句。
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呵呵