Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

File Name Converter

Posted on July 18, 2013October 26, 2015 By David Kittell

<% @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.

Related

ASP Code VB

Post navigation

Previous post
Next post

Related Posts

Create Shortcut (VB, VB.Net, PowerShell)

Posted on December 14, 2013December 10, 2019

Sub Create_ShortCut(ByVal TargetPath As String, ByVal ShortCutPath As String, ByVal ShortCutname As String, Optional ByVal WorkPath As String = "", Optional ByVal Window_Style As Short = 0, Optional ByVal IconNum As Short = 0) Dim VbsObj As Object VbsObj = CreateObject("WScript.Shell") Dim MyShortcut As Object ShortCutPath = ShortCutPath MyShortcut =…

Read More

Format Zip Code Properly

Posted on November 11, 2013October 26, 2015

Sometimes a zip code is presented in a database with all nine numbers in the same column that has only five numbers. This query below will assist in formatting the numbers properly. SELECT CASE WHEN len(zip) = 10 AND substring(zip, 6, 1) = ‘-‘ THEN zip WHEN len(zip) = 5…

Read More

User Registration – Check Username Availability

Posted on July 21, 2014October 26, 2015

This is a simple example of how to check for the existence of a username prior to letting someone select a username. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="UserRegistration.aspx.cs" Inherits="UserRegistration" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>User Registration – Check Username Availability</title> </head> <body> <form…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes