Add to Favorites    Make Home Page 1475 Online  
 Language Categories  
 Our Services  

Home » ASP Home » Files Home » Recurse and Rename

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title Recurse and Rename
Author Jeremy Nevill
Author Email jeremy [at] nevill.co.uk
Description Recurses down a directory tree and renames files
Category ASP » Files
Hits 380190
Code Select and Copy the Code
<%@ Language=VBScript %> <% Option Explicit '====================================================================================== 'Script: RecurseAndRename.asp 'Version: 1.1 'Function: Recurses down a directory tree and renames ' any files in the directories that have blanks in their filename. ' ' ### ' ### MAKE SURE TO READ THE INSTRUCTIONS BELOW BEFORE RUNNING THIS SCRIPT ' ### ' 'Author: Jeremy Nevill ' [email protected], October 2000 'Website: http://www.lisys.com - ASP/SQL/XML Development, Scripts and Tools 'Copyright: Copyright � 2000 Lateral Information Systems Ltd, All Rights Reserved ' 'License: RecurseAndRename.asp may be used and modified free of charge by anyone ' so long as this copyright notice and the comments above remain intact. ' By using this code you agree to indemnify Lateral Information Systems Ltd ' from any liability that might arise from it's use. ' Selling the code for this program without prior written consent is ' expressly forbidden. ' Obtain permission before redistributing this software over the Internet or ' in any other medium. In all cases copyright and header must remain intact 'Last Upd: 10/01/01 Added safety bEnabled variable, also made script rename in start dir. '======================================================================================= ' ' INSTRUCTIONS - 10/01/01 ' ======================= ' This script renames files, as a couple of people have run it and had problems ' I have modified the script to require the user to modify the bEnabled ' variable to true for renaming to actually take place. (Go to Line 42 to enable this script) Dim bEnabled Dim fso 'as file system object Dim nTotalFilesRenamed 'as integer bEnabled=False '**** Set to false the script will not rename files, change this to true for renaming to take place. Server.ScriptTimeout=120 'Set the page timeout to 2 mins Const sStartDirectory="c: emp" '*** This is the starting directory 'Be carefull where you start as this 'script renames any file under this dir 'that contain blanks. *** 'Setup the file system object Set fso = Server.CreateObject("Scripting.FileSystemObject") %> <HTML> <HEAD> <title>Recurse And Rename (http://www.lisys.com)</title> <style> Body { background-color: #FFFFFF; color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif, "MS sans serif"; } TD { background-color: #FFFFFF; color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif, "MS sans serif"; font-size: 70% } .TableTitle { background-color: #FFFFCE; } .Summary { background-color: #FFCE9C; } .Rename { background-color: #FFFF9C; } </style> </HEAD> <BODY> <table width="60%" border="1" align="center" cellspacing="0" cellpadding="2"> <tr> <td Class="TableTitle"><b>Recurse And Rename - Script from <a href="http://www.lisys.com">lisys.com</a></b><br> <i>Start Directory: <%=sStartDirectory %></i></td> </tr> <% If bEnabled=False Then Response.Write "<tr><td class=""TableTitle""><b>This script is disabled, please read the instructions (only a couple of lines) to enable it!</b></td></tr>" & vbCrLf End If 'Start with current folder Response.Write "<tr><td>" & sStartDirectory & "</td></tr>" & vbCrLf Call RenameFilesStripBlanks(sStartDirectory) 'Call the RecurseFolder function to recurse down from the start directory. Call RecurseFolder(sStartDirectory, fso) %> <tr> <td Class="TableTitle">Total Files Renamed: <%=nTotalFilesRenamed %></i></td> </tr> </table> </BODY> </HTML> <% Sub RecurseFolder(sPath, fso) '=========================================================== 'Page: RecurseFolder(sPath, fso) 'Function: Recurses down folders from sPath calling the ' function to rename files with blanks '=========================================================== Dim fFolder, fSubFolders, fSubFolder Set fFolder = fso.GetFolder(sPath) Set fSubFolders = fFolder.SubFolders 'Now recurse for each subfolder in the sPath folder... For Each fSubFolder In fSubFolders Response.Write "<tr><td>" & sPath & "" & fSubFolder.name & "</td></tr>" & vbCrLf 'Rename all files in this directory where filename contains blanks RenameFilesStripBlanks(sPath & "" & fSubFolder.name) '*** Call self to recurse down folders Call RecurseFolder(sPath & "" & fSubFolder.name, fso) Next End Sub Sub RenameFilesStripBlanks(sPath) '=========================================================== 'Page: RenameFilesStripBlanks(sPath) 'Function: Renames all files in sPath directory where ' file contains a blank space - remove this space '=========================================================== Dim nFilesRenamed, drive, folder, filelist, file, sNewFile nFilesRenamed=0 Set drive = Server.CreateObject("Scripting.FileSystemObject") Set folder = drive.GetFolder(sPath) Set filelist = folder.files For Each file In filelist sNewFile=Replace(file.name," ","") If (sNewFile<>file.name And bEnabled=True) Then Response.Write "<tr><td class=""Rename"">" & "Rename:" & file.name & " to " & sNewFile & "</td></tr>" 'If the new filename does not exist then change file, else flag to user If Not(fso.FileExists(sPath & "" & sNewFile)) Then 'Rename the file file.name = sNewFile Else Response.Write "<tr><td class=""Rename"">" & "Renamed File Exists:" & file.name & " to " & sNewFile & "</td></tr>" End If 'Increment the files renamed counter nFilesRenamed=nFilesRenamed + 1 End If Next 'Inform user of number of files renamed in current directory If nFilesRenamed<>0 Then Response.Write "<tr><td class=""Summary"">" & nFilesRenamed & " Renamed" & "</td></tr>" & vbCrLf End If 'Increment the total files renamed counter nTotalFilesRenamed=nTotalFilesRenamed + nFilesRenamed End Sub %>

Related Source Codes

Script Name Author
��������������������� VyomWorld
Resistor color code reader A.Chermarajan.
Telephone Directory dhivya
card swapping game (Mini Project) nityanand
simple hangman-pascalsource Seabert
college dirtectory (Mini Project) msridhar
Poll Application John van Meter
ASP Daily Hit Counter. Tejaskumar Gandhi
To avoid null in asp environment using sql Sami
Maklumbalas webmaster
poll John van Meter
EasyASP Template Engine. TjoekBezoer
Basic Calculator using HTML & Javascript. Patrick M. D Souza
What servers support ASP ? VyomWorld
What is ASP? VyomWorld

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=335


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review