Creating Folders

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
MCorn said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top