<%
'==================================================================================
'== 설명 : 폴더 존재 여부를 체크하여 폴더 만들기
'== 이름 : ChkDirecoty(dir, gubun, dir_status)
'== 변수 : dir(경로명), gubun(폴더구분자),dir_status(가상경로:v, 물리적경로:p)
'== 반환 : String
'===================================================================

Sub ChkDirectory(dir,gubun, dir_status)
Dim objFile, objStream
Dim i,tmp

Set objFile = Server.CreateObject("Scripting.FileSystemObject")
for i = 0 to ubound(split(dir,gubun))-1
tmp = tmp&split(dir,gubun)(i)&gubun

If dir_status = "v" then
IF not(objFile.folderexists(Server.MapPath(tmp))) then
objFile.createfolder(Server.MapPath(tmp))
End If
Elseif dir_status = "p" then
IF not(objFile.folderexists(tmp)) then
objFile.createfolder(tmp)
End If
End If
next
Set objFile = Nothing
End Sub

'===================================================================
'== 설명 : 화일 지우기
'== 이름 : DeleteTxtFile(FileName, path_status)
'== 변수 : FileName : 전체 화일명, status : 파일경로 형태(v:가상경로,r:물리적경로)
'== 반환 : String
'===================================================================
Sub DeleteTxtFile(FileName, path_status)
Dim objFile, objStream, Err

' On Error Resume Next
Set objFile = Server.CreateObject("Scripting.FileSystemObject")
If path_status = "v" then
objFile.DeleteFile Server.MapPath(FileName)
Else
objFile.DeleteFile FileName
End If

Set objFile = Nothing
' Err.Clear
End Sub


'===================================================================
'== 설명 : 고유한 파일이름으로 변환
'== 이름 : GetUniqueName
'== 변수 : String
'== 반환 : String
'===================================================================

Function GetUniqueName(byRef strFileName, DirectoryPath)
Dim strName, strExt
strName = Mid(strFileName, 1, InstrRev(strFileName, ".") - 1) ' 확장자를 제외한 파일명을 얻는다.
strExt = Mid(strFileName, InstrRev(strFileName, ".") + 1) '확장자를 얻는다

Dim fso
Set fso = Server.CreateObject("Scripting.FileSystemObject")

Dim bExist : bExist = True
'우선 같은이름의 파일이 존재한다고 가정
Dim strFileWholePath : strFileWholePath = DirectoryPath & "" & strName & "." & strExt
'저장할 파일의 완전한 이름(완전한 물리적인 경로) 구성
Dim countFileName : countFileName = 0
'파일이 존재할 경우, 이름 뒤에 붙일 숫자를 세팅함.

Do While bExist ' 우선 있다고 생각함.
If (fso.FileExists(strFileWholePath)) Then ' 같은 이름의 파일이 있을 때
countFileName = countFileName + 1 '파일명에 숫자를 붙인 새로운 파일 이름 생성
strFileName = strName & "-" & countFileName & "." & strExt
strFileWholePath = DirectoryPath & "" & strFileName
Else
bExist = False
End If
Loop
GetUniqueName = strFileWholePath
End Function


'===================================================================
'== 설명 : 클라이언트에서 업로드된 파일명 리턴
'== 이름 : ChkFileName
'== 변수 : String
'== 반환 : String
'===================================================================

Function ChkFileName(name)
Dim tmpName, tmpExt, arrTmpName, tmpFileName

tmpName = Mid(name, 1, InstrRev(name, ".") - 1)
tmpExt = Mid(name, InstrRev(name, ".") + 1)

arrTmpName = split(tmpName,"")
tmpName = arrTmpName(Ubound(arrTmpName))
tmpFileName = tmpName&"."&tmpExt

ChkFileName = tmpFileName
End Function




'==================================================================================
'== 설명 : 화일 존재 여부를 체크하여 리턴
'== 이름 : ChkDirecoty(dir_status, filePath)
'== 변수 : dir_status(가상경로:v, 물리적경로:p), filePath(디렉토리포함)
'== 반환 : 존재(true), 없음(false)
'===================================================================

Function ChkFileExist(dir_status, filePath)
Dim objFile, tmpFile

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

IF dir_status="v" then
tmpFile = Server.MapPath(filePath)
Else
tmpFile = filePath
End IF

If objFile.FileExists(tmpFile) then
chkFileExist=true
else
chkFileExist=false
End If

Set objFile = Nothing

End Function

%>
2009/05/26 13:37 2009/05/26 13:37

Trackback Address :: https://youngsam.net/trackback/490