File Name Converter

| |

<% @LANGUAGE = VBSCRIPT %>
<%Option Explicit%>

<%

‘ File Name Move and Converter
‘ Written by Cristiano Guglielmetti: guglielmetti@tin.it
‘ Dec.2001
‘ This script moves and renames files into a webserver from a dir to another dir
‘ especially designed for large numbers of pictures files

Response.Write "<html>" & VbCrLf & "<head>" & VbCrLf
Response.Write "<title>File Move-Name-Converter" & VbCrLf
Response.Write "</head>" & VbCrLf & "<body>" & VbCrLf

‘ Declare variables

Dim gbolGoProcedure
Dim strFromDir
Dim strTargetDir
Dim objFS
Dim objRootFolder
Dim objFile
Dim strFileNameLen
Dim strPrevFileName
Dim strFileExt
Dim strFileNameCount
Dim strNewFileName
Dim strRealCount

gbolGoProcedure = False

‘ Setup procedure execution
If (Request.Form("GoButton")) = "GO PROCEDURE" then

‘ Declare directories

strFromDir = "[Disk]:Dir1UnderDir1UnderDir2"
strTargetDir = "[Disk]:Dir1UnderDir1UnderDir2"

‘ Set to zero filecount before move

strRealCount = 0

‘ Count existing files in the target dir (starting from 100001)

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

Set objRootFolder = objFS.GetFolder(strTargetDir)

strFileNameCount = 100001

‘ Remove from filecount Windows imagetumbs DB (Thumbs.db)

For each objFile in objRootFolder.Files

If objFile.Name = "Thumbs.db" then strFileNameCount = StrFileNameCount – 1
strFileNameCount = strFileNameCount + 1

Next

‘ Move and rename files from FromDir to TargetDir

Set objRootFolder = objFS.GetFolder(strFromDir)

For each objFile in objRootFolder.Files

strFileNameLen = Len (objFile.Name)

If Mid (objFile.Name,(strFileNameLen – 3),1) = "." then
strFileExt = right(objFile.Name, 4)
Else
strFileExt = right(objFile.Name, 5)
End If

strPrevFileName = objFile.Name
strNewFileName = strFileNameCount & strFileExt

objFile.Move strTargetDir & strNewFileName

Response.Write "Conv: " & strPrevFileName & " > To: " & strNewFileName & "<br>" & vbCrLF
strFileNameCount = strFileNameCount + 1
strRealCount = strRealCount + 1

Next

Response.Write "<p><b>Have been moved and renamed " & (strRealCount) & " files</B>" & vbCrLf

‘ Destroy objects

Set objRootFolder = Nothing
Set objFS = Nothing

gbolGoProcedure = True

End If

‘ Setup user interface

If gbolGoProcedure Then
Response.Write("<p><b>Procedure MOVE AND RENAME close</b>") & vbCrLf

Else
Response.Write("<form method=""post"" action=""FileNameConverter.asp"" ID=form1 name=""form1"">") & vbCrLf
Response.Write("<input type=""SUBMIT"" value=""GO PROCEDURE"" ID=""GoButton"" name=""GoButton"">") & vbCrLf
Response.Write("</form>") & vbCrLf
Response.Write("<p><b>Attention: click the button to start Move and Rename procedure</b>") & VbCrLf
End If

Response.Write "</body>" & VbCrLf & "</html>"

%>

Originally Posted on July 18, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.