Batch subfolder renaming

B

Bruce

Hi,

Part of my database processing is to copy a template folder structure
from the Masters into the Project folder and prefix all these copied
folders with the Project number.

I have executed the first part ok with the CopyFolder function.

The second part is a bit harder. I need to count all the subfolders,
then loop through them one at a time prefixing them with the Project
Number to subfolders two levels deep (I didn't set up the system, I
just gotta work with it).

I've tried using the Folder object but I don't know how to specify a
directory.
I've tried the looping method using the Dir function as provided by
Microsoft help, but I can't specify a deep enough structure.

The logic language of what I want to do is:

For i = 1 to NewFolder(Level 2).Subfolders.Count
With NewFolder(Level 2)
.Subfolder(i).Name = strProjectNumber & " " & _
.Subfolder(i).Name
End With
Next i

Any ideas?

Cheers,

Bruce P Walker
 
B

Bruce

[email protected] (Bruce) wrote in message
Never mind, I solved it with the following code:

Dim strDirectory, strProjectRef As String
Dim strFolderName, strDestination As String
Dim fso As Object
Dim fdrNewFolder As Folder
Set fso = CreateObject("Scripting.FileSystemObject")

'Copy Project Folder Setup across and rename
fso.copyfolder strFolderSetup, strDirectory, False

'Set directory to "\Drawings"
strDirectory = strDirectory & strSub1

'Rename appropriate subfolders with Project Number
For i = 1 To 2
strFolderName = Dir(strDirectory, vbDirectory) ' Retrieve the
first entry.
Do While strFolderName <> ""
' Ignore the current directory and the encompassing directory.
If strFolderName <> "." And strFolderName <> ".." Then
' Use bitwise comparison to make sure strFolderName is a
directory.
If (GetAttr(strDirectory & strFolderName) And vbDirectory)
= vbDirectory Then
Name strDirectory & strFolderName As strDirectory &
strProjectNo & strFolderName
End If
End If
strFolderName = Dir ' Get next entry.
Loop
strDirectory = strDestination & strProjectRef & "\"
Next i
 
D

Douglas J. Steele

Just a comment. I'll bet you think that

Dim strDirectory, strProjectRef As String
Dim strFolderName, strDestination As String

declares 4 string variables. It doesn't: strDirectory and strFolderName are
both being declared as variants.

To get them all as strings, you need:

Dim strDirectory As String, strProjectRef As String
Dim strFolderName As String, strDestination As String
 
Top