메뉴 건너뛰기

Dev tips

ASP [ASP] 특정폴더 내 파일들 이름 바꾸기

taknim 2008.07.26 01:04 조회 수 : 8125 추천:2056

<%
defaultpath = "D:\"
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set oFold = fso.GetFolder(defaultpath)
Set oFile = oFold.Files

For Each i In oFile
        On Error Resume Next
        name = i.Name
        extonly = Mid(name, InstrRev(name, ".") + 1)
        nameonly = Left(name, InstrRev(name, ".") - 1)
        rename = Left(nameonly, Len(nameonly) - 3)
'        con = Right(nameonly, 3)
        con2 = Right(nameonly, 6)
        If con2 = "(1)(1)" Then
'                fso.MoveFile defaultpath & name, defaultpath & rename & "." & extonly
                If Err.Number = 0 Then
                        Response.Write "<font color=blue>" & name & "=>" & rename & "." & extonly & "</font><BR>"
                Else
                        Response.Write "<font color=red>" & name & "=>" & rename & "." & extonly & "</font> - (" & Err.Number & ") " & Err.Description & "<BR>"
                End If
                Err.Clear
'        Else
'                Response.Write "<font color=red>" & name & "</font><BR>"
        End If

        On Error Goto 0
Next

Set oFile = Nothing
Set oFold = Nothing
Set fso = Nothing
%>