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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Folder script 2

Status
Not open for further replies.

ITSTOAST

Technical User
Mar 3, 2005
71
GB
Hi all I have this script that I need to change so that it has a wild card function allowing it to create a folder in all the folders within one folder, my script so far is:

On Error Resume Next

Dim Answer1, Answer2, Answer3

Set wn = WScript.CreateObject("WScript.Network")
Set fs = CreateObject("Scripting.FileSystemObject")
Set ws = CreateObject("WScript.Shell")

Answer1 = InputBox("Enter the name of the folder you wish to create")



' The following lines will create a folder and two
' subfolders on c: from the answers given in the input
' boxes above

fs.CreateFolder ("d:\pupils\all\my documents\tech\year 5\" & Answer1)






Only the good die young, me I'm here forever :)
 
This should do it:

' FolderCreate.vbs - Create folders within all subfolders.

Option Explicit

Const TARGFOLDER="d:\pupils\all\my documents\tech\year 5"

Dim FSO,WSH,sNewFolder,oFolder,oSubFolder,sFullPath
Set WSH=CreateObject("WScript.Shell")
Set FSO=CreateObject("Scripting.FileSystemObject")

sNewFolder=InputBox("Enter the name of the folder you wish to create")

If Not FSO.FolderExists(TARGFOLDER) Then
WScript.Echo "Folder '" & TARGFOLDER & "' does not exist."
Else
Set oFolder=FSO.GetFolder(TARGFOLDER)
For Each oSubFolder In oFolder.SubFolders
sFullPath=oSubFolder.Path
If Right(sFullPath,1)<>"\" Then sFullPath=sFullPath & "\"
sFullPath=sFullPath & sNewFolder
FSO.CreateFolder sFullPath
Next
End If

 
Thanks ANTYKREIST i'll have a go

Only the good die young, me I'm here forever :)
 
Its brill stars all round, thanks AntiChrist (ANTYKREIST)

Only the good die young, me I'm here forever :)
 
The script works great, in a slight variation on a theme how would you move a folder including its contents to a simular target as the folder creation VBS that you helped me with?
This is not essential but I just wondered if it was possible to mass "post" a folder and its contents to a group of folders, thanks for your help

Only the good die young, me I'm here forever :)
 
Take a look at the CopyFolder method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi any ideas how to use this to also Delete a folder using the same method?


Only the good die young, me I'm here forever :)
 
Take a look at the DeleteFolder method

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi how do you wild card the copy folder funtion so it copies to every folder in a destination. Simular to the create folder script in the threads above? thanks

Only the good die young, me I'm here forever :)
 
STUCK STUCK STUCK....I have fiddled poked and sworn but I just don't have the skill to code this.
It must be possible to copy a folder full of files to a set of subfolders in another directory. I have tried changing the create folders script kindly provided by antykreist, but with no success.HELP! stressed school tech

Only the good die young, me I'm here forever :)
 
Can you please post your actual code and say us where you're stuck ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi PHV the code in this thread creates a folder and will place it in the path as shown in the code.
I can use this snippet,

Const OverWriteFiles = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFolder "G:\SERVER FILES\Folder creator\FOLDER TRANSFER" , "C:\PUPILS\ALL\MY DOCUMENTS\TECH\YEAR 5" , OverWriteFiles

This copies a folder and its entire contents from a folder called "TRANSFER" to a single destination, I Have tried placing the copyfolder into the first script but as I have no concept of the form to use it fails miserably. I looked at the site you recomended but no luck.
Thanks Stressed school tech

Only the good die young, me I'm here forever :)
 
And you want to copy the folder called "TRANSFER" WHERE ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
This almost works except it transfers the Folder Called TRANSFER as well so I am almost there

Dim fso
Dim path
Dim oFolder
Dim oSubFolder
Const OverwriteExisting = True

Set fso = createobject("Scripting.FileSystemObject")
Folder = "G:\SERVER FILES\Folder creator\FOLDER TRANSFER"
Path = "C:\PUPILS\ALL\MY DOCUMENTS\TECH\YEAR 5"
Set oFolder = fso.GetFolder(Path)
Set colSubfolders = oFolder.Subfolders

For Each oSubfolder in colSubfolders
fso.CopyFolder Folder, path & "\" & oSubFolder.Name & "\", OverwriteExisting
Next

Only the good die young, me I'm here forever :)
 
You want this ?
Const OverWriteFiles = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFolder "G:\SERVER FILES\Folder creator\FOLDER TRANSFER\*" , "C:\PUPILS\ALL\MY DOCUMENTS\TECH\YEAR 5\" , OverWriteFiles

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks again PVH have a star cos u r

Only the good die young, me I'm here forever :)
 
I am going to try and add an input box to this script to allow me to specify the destination without going into the code each time I change the destination folder, fingers crossed.....

Only the good die young, me I'm here forever :)
 
My (our) finished script.

ITSTOASTS copy folder script with thanks to PHV & ANTYKREIST



Dim fso
Dim path
Dim oFolder
Dim oSubFolder
Const OverwriteExisting = True

transfer =Inputbox ("Enter folder containing files to transfer (TYPE or PASTE)")

Path =Inputbox("Enter Target Folder (TYPE or PASTE)")

Set fso = createobject("Scripting.FileSystemObject")
Folder = transfer & "\*"

Set oFolder = fso.GetFolder(Path)
Set colSubfolders = oFolder.Subfolders

For Each oSubfolder in colSubfolders
fso.CopyFolder Folder, path & "\" & oSubFolder.Name & "\", OverwriteExisting
Next

Only the good die young, me I'm here forever :)
 
Hi PHV
I have seen some of your threads on browsing for a folder, how could I intergrate that into this script?
To browse for the Source and destination folders?
Thanks Less stressed school tech( well it is the weekend)

Only the good die young, me I'm here forever :)
 
Still looking for a way to add a browse function to this script to perfect it.

Only the good die young, me I'm here forever :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top