Creating Folders



MCorn
07-10-2005, 12:22 AM
Hi,
Is there a way to create a new folder in a parent folder and have the new
folder populate into all child folders within the parent? (without having to
manually go and add the new folder indivually)

Thanks for any help or advice!
MCorn

tfw48079
07-10-2005, 12:22 AM
I think there is.

"MCorn" wrote:

> Hi,
> Is there a way to create a new folder in a parent folder and have the new
> folder populate into all child folders within the parent? (without having to
> manually go and add the new folder indivually)
>
> Thanks for any help or advice!
> MCorn

Torgeir Bakken \(MVP\)
07-10-2005, 12:23 AM
MCorn wrote:

> Hi,
> Is there a way to create a new folder in a parent folder and have
> the new folder populate into all child folders within the parent?
> (without having to manually go and add the new folder indivually)
Hi,

You can use a VBScript for this.

Put the VBScript below in a .vbs file.

You can now drag and drop the parent folder onto the VBScript, or send
in the folder name on the command line. The script will ask for the new
folder name to populate the subfolders with.

Alternatively, you can configure it so you can use right click/Send To.

Do like this:

Create a file called e.g. "Populate Folder.vbs" containing the script
below and create a shortcut to it in the SendTo folder (or just put
the file itself in the SendTo folder, but then you will see the .vbs
extension, at least if you have set Explorer to show file extensions).

This way, you can right click a link file in Explorer, use the SendTo
selection "Populate Folder".

To open the SendTo folder to put your script shortcut into, run this
from the Start\Run menu (include the quotes!):

"%USERPROFILE%\SendTo"


'--------------------8<----------------------

' Script that will populate all subfolders with a new folder
'
' It supports the following operations:
'
' Dragging of *one* folder to the script icon
' or add the folder to the command line.
' All subfolders in this folder will then be enumerated
' and the new folder will be added to them

Set oArgs = WScript.Arguments

sTitle = "Populate folder"
sErrMsg = "Error: You need to supply a folder path as input!"
If oArgs.Count <> 1 Then
MsgBox sErrMsg, vbCritical + vbSystemModal, sTitle
Wscript.Quit
Elseif oArgs.Count = 1 And Not oFSO.FolderExists(oArgs(0)) Then
MsgBox sErrMsg, vbCritical + vbSystemModal, sTitle
Wscript.Quit
End If

sNewFolder = InputBox("Enter the folder name to be populated", sTitle)

If sNewFolder = "" Then
WScript.Quit
End If

sFolder = oArgs(0)

Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oFolder = oFSO.GetFolder(sFolder)

On Error Resume Next
For Each oSubFolder In oFolder.SubFolders
oFSO.CreateFolder oSubFolder.Path & "\" & sNewFolder
Next

MsgBox "Finished!", vbInformation + vbSystemModal, sTitle

'--------------------8<----------------------

WSH 5.6 documentation (local help file) can be downloaded
from here if you haven't got it already:
http://msdn.microsoft.com/downloads/list/webdev.asp


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx


Creating Folders