Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enumerate all subfolders named a certain name and rename

Status
Not open for further replies.

jgrimes

MIS
Mar 20, 2003
3
US
Need Help, new to VBscript.

I need a script that enumerates all subfolders of a folder named "date" no matter how many levels down and renames folder to yesterday's date in the following format 03_03_19 (year, month, day)

Have mercy need quickly users tired of renaming manually each day.

Thanks
 
Try a keyword search (see tab at the top of the forum) for something like "folder" and/or "traversal." Be sure to go back 6 months or more to get good search coverage.

You might also try requesting an all words search like "directory traversal" or "folder traversal" or even "recursive folder" since this kind of thing is commonly done recursively.

This has been covered here several times already.
 
Thanks for your response. I searched as you suggested and I came up with something I believe is close. Thread707-437171.

However, since I'm not a programmer this is way above my head, so here is my stupid question of the day. Where the thread states ' Add reference to Microsoft Scripting Runtime before running this code. What does this mean? I'm sure this is programming 101 but like I stated earlier, I'm new to all this. Thanks for your understanding and help.
 
That thread you saw was over in the VBA Forum. You don't use references the same way in VBScript as you do in VB or VBA. Sorry the search didn't pan out for you. I know they're working on improvements to these searches.

Here's an old thread of mine that came up: thread329-370893

Keep in mind that there were some goofs so you need to go all the way through the thread to pick up the corrections. You can chop out all of the stuff about MDB versions and insert your renaming logic.

The problem is, it might all be a bit much if you aren't a programmer.

There are many other renditions of the same thing here too so you might try additional searches within this forum. Avoid using the "Search" box at the top of the page - this will get you in trouble.

Instead use the Keyword Search "folder tab" thingy below it. Web designers think they're soooo cute sometimes.
 
A coworker of mine - wrote this for me and here is how he did it.

-----------------------------------------------------------

' Renames the 'date' folder in the USGLxxxx directories to the previous day's date
' 03/28/03 Mark W. Zeininger

Option Explicit

Const FolderName = "DATE"
Const FoldersRoot = "F:\NVSRPTS\PRD\REP_OUT"
Const ForReading = 1, ForWriting = 2, ForAppending = 8 ' Open File constants

Dim fileObject, wshShell

' Create file and Shell objects to work with throughout the program
Set fileObject = CreateObject("Scripting.FileSystemObject")
Set wshShell = WScript.CreateObject("WScript.Shell")

' Loop to iterate folders
CheckUSGL

Sub CheckUSGL()
' Iterates through USGLxxxx folders for a 'DATE' folder
' 03/28/03 Mark W. Zeininger
Dim USGLfolder, folderCollection, folderObj

Set USGLfolder = fileObject.GetFolder(FoldersRoot)
Set folderCollection = USGLfolder.SubFolders

For Each folderObj in folderCollection
If fileObject.FolderExists(folderObj.Path & "\" & folderName) then
RenameFolder folderObj.Path & "\" & folderName
End If
Next

Set folderCollection = Nothing
Set USGLfolder = Nothing
End Sub

Sub RenameFolder(folderPath)
' Renames the 'DATE' folder to the previous days date
' 03/28/03 Mark W. Zeininger
Dim dateFolder

Set dateFolder = fileObject.GetFolder(folderPath)

dateFolder.Name = DateTime

Set dateFolder = Nothing
End Sub


Function DateTime()
' Returns a Date Time string in YYYY_MM_DD
' 03/28/03 Mark W. Zeininger
Dim CurrDateTime

CurrDateTime = Now() - 1
DateTime = Year(CurrDateTime) & "_" & LeadingZero(Month(CurrDateTime)) _
& "_" & LeadingZero(Day(CurrDateTime))
End Function

Function LeadingZero(digitStr)
' If single digit, add a leading zero
' 09/11/02 Mark W. Zeininger
If Len(digitStr) = 1 then
LeadingZero = "0" & digitStr
Else
LeadingZero = digitStr
End If
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top