Search code examples
asp-classicdirectorycopying

How to create target directory structure for copy files in classic ASP?


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

Solution

  • 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