1

我想将文件复制到目标目录。使用文件系统对象的 copyFile 命令很简单。但我需要一些增强,比如,

如果目标目录不存在,那么它将创建目标目录,然后复制一个文件。

你能帮我实现它吗?

让我知道是否还有其他方法可以做到这一点。

谢谢。

解决方案:

'Create folder if it doesn't exist
If not oFSO.FolderExists(sDestinationFolder) then
    oFSO.CreateFolder(sDestinationFolder)
End If
4

2 回答 2

2

这是我这项工作的基本职能:-

Dim gfso : Set gfso = Server.CreateObject("Scripting.FileSystemObject")

Public Sub CreateFolder(path)

  If Len(path) = 0 Then Err.Raise 1001, , "Creating path: " & path & " failed"

  If Not gfso.FolderExists(path) Then
    CreateFolder gfso.GetParentFolderName(path)
    gfso.CreateFolder path
  End If

End Sub
于 2009-09-08T14:11:28.743 回答
1

像这样的东西:

Set fs=Server.CreateObject("Scripting.FileSystemObject")

//Create folder if it doesn't exist
If fs.FolderExists("YOURFOLDERPATH") != true Then
    Set f=fs.CreateFolder("YOURFOLDERPATH")
    Set f=nothing
End If

//Copy your file

set fs=nothing

W3Schools 有很多关于如何使用 FileSystemObject [这里][1] 的示例。

编辑:

Set fs=Server.CreateObject("Scripting.FileSystemObject")

folders = Split("YOURFOLDERPATH", "\")
currentFolder = ""

//Create folders if they don't exist
For i = 0 To UBound(folders)
    currentFolder = currentFolder & folders(i)
    If fs.FolderExists(currentFolder) != true Then
        Set f=fs.CreateFolder(currentFolder)
        Set f=nothing       
    End If      
    currentFolder = currentFolder & "\"
Next

//Copy your file

set fs=nothing
于 2009-09-07T15:14:35.427 回答