Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Renaming Folders

Is there a way to rename all files and folders within a directory to
all lower case letters (while keeping the same name)?

Thanks,
-- Dan

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Renaming Folders

Try something like the following. It renames each folder to begin with "___"
and then renames again to the lower case name. This assumes you have no
folders whose name begins with "___". Change C_FOLDER_NAME to the full name
of the folder whose subfolder are to be renamed.

Const C_FOLDER_NAME = "C:\Test" '<<< CHANGE
Dim FSO As Object
Dim TempName As String
Dim FolderObj As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
For Each FolderObj In FSO.GetFolder(C_FOLDER_NAME).SubFolders
TempName = LCase(FolderObj.Name)
FolderObj.Name = "___" & FolderObj.Name
FolderObj.Name = TempName
Next FolderObj
Set FSO = Nothing


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"Dan R." wrote in message
ups.com...
Is there a way to rename all files and folders within a directory to
all lower case letters (while keeping the same name)?

Thanks,
-- Dan



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Renaming Folders

Wow, very impressive, I wasn't expecting any feedback on this one...

Thanks a lot Chip,
-- Dan

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Renaming Folders

Dan,

I didn't read your original post quite right. The code I replied with will
only do one level of subfolders below the C_FOLDER_NAME, and it won't do
files. The code below will rename all files and all levels of subfolders.
As before, change C_FOLDER_NAME to the appropriate folder name, and run
StartRename. It will call DoOneFolder and that calls itself recursively to
do all files and all levels of subfolders.

Sub StartRename()
Const C_FOLDER_NAME = "C:\Test"
Dim FSO As Object
Dim TopFolder As Object
Set FSO = CreateObject("Scripting.FileSystemObject")

Set TopFolder = FSO.getfolder(C_FOLDER_NAME)
DoOneFolder TopFolder
End Sub


Sub DoOneFolder(FolderObj As Object)
Dim FileObj As Object
Dim SubFolderObj As Object
Dim LCName As String

For Each FileObj In FolderObj.Files
LCName = LCase(FileObj.Name)
FileObj.Name = "___" & FileObj.Name
FileObj.Name = LCName
Next FileObj

For Each SubFolderObj In FolderObj.subfolders
LCName = LCase(SubFolderObj.Name)
SubFolderObj.Name = "___" & SubFolderObj.Name
SubFolderObj.Name = LCName
DoOneFolder SubFolderObj
Next SubFolderObj
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)



"Dan R." wrote in message
ups.com...
Wow, very impressive, I wasn't expecting any feedback on this one...

Thanks a lot Chip,
-- Dan



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Renaming Folders

Perfect, works great!

Thanks again,
-- Dan

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i use vba to zip folders? scouse1 Excel Programming 1 June 14th 06 11:12 PM
List of Folders marianne Excel Programming 10 June 7th 06 11:48 AM
Renaming folders and changing links accordingly fullers Excel Programming 1 January 18th 06 11:54 AM
Trouble renaming Folders asmenut Excel Programming 2 October 31st 04 11:44 PM
Renaming folders Robin Clay[_3_] Excel Programming 6 August 12th 04 05:12 PM


All times are GMT +1. The time now is 08:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"