如何在经典 ASP 中创建复制文件的目标目录结构?

发布于 2024-08-04 06:21:04 字数 333 浏览 6 评论 0原文

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

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

你能帮我实现它吗?

让我知道是否还有其他方法可以做到同样的事情。

谢谢。

解决方案:

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

I want to copy a file to target directory.
It is simple with copyFile command of File system object.
But I need some enhancement like,

If target directory is not exist then it'll create target directory and then copy a file.

Can you help me achieve it?

Let me know if there are other ways to do same.

Thanks.

Solution:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜味拾荒者 2024-08-11 06:21:04

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

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

This is my basic function for this job:-

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
﹏半生如梦愿梦如真 2024-08-11 06:21:04

像这样的事情:

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

Something like this:

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 has lots of examples on how to use the FileSystemObject [here][1].

EDIT:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文