2009-09-07 3 views
1

파일을 대상 디렉토리에 복사하려고합니다. 파일 시스템 오브젝트의 copyFile 명령으로 간단합니다. 하지만 다음과 같은 몇 가지 기능이 필요합니다.클래식 ASP에서 파일 복사를위한 대상 디렉토리 구조를 만드는 방법은 무엇입니까?

대상 디렉토리가 존재하지 않으면 대상 디렉토리를 만든 다음 파일을 복사합니다.

도와 주시겠습니까?

동일한 작업을 수행 할 수있는 다른 방법이 있다면 알려주십시오.

감사합니다.

솔루션 :이 같은

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

@Vikas : 단지 당신이 코멘트는, 당신의 문제의 해결책을보고 혼란 ' 세트를 제거했을 때 대답이 충분했을 것입니다. – AnthonyWJones

답변

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 
+0

Ooo, 재귀 적 - 이것이 완료되었습니다! – BlueSix

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 

W3 스쿨은 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 
+0

음, 정확히 하나의 폴더를 만들 경우에만 작동합니다. 여러 폴더를 만들 때이 작업이 필요합니다. 예 :/export/new/new1/new2 등을 포함하고 export 폴더 만 존재한다고 생각하십시오. – Vikas

+0

내 VB는 녹슨 것보다는 조금 낫지 만 이것 (내 최신 편집 참조)은 작동하지 않습니까? – Tchami

관련 문제