![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Script going too deep into subfolders, need help! OK, I found the following script, and it does exactly what I want it to do, except it creates the subfolder SaveHere in every subfolder. What I want it to do, is only create a SaveHere folder inside every folder one level deeper than c:\temp. Like in C:\temp\1, C:\temp\2 i want it to create a SaveHere folder, but not in C:\temp\1\a or c:\temp\1\a\z. I hope that makes sense. Can someone help me out? I'm not very good at the whole recursive stuff yet. Dim arrNewFolders arrNewFolders=Array(_ "SaveHere") newfolderpath = "C:\TEMP" mysub(newfolderpath) '**********start of recursive Sub routine ************* Sub mysub(path) Dim filesys, newfolderpath, RootFolder, FolderColl, SubFolder wscript.echo "Processing " & path Set filesys=CreateObject("Scripting.FileSystemObject") Set RootFolder = filesys.GetFolder(path) ' Process subfolders if RootFolder.SubFolders.Count>0 then For Each SubFolder In RootFolder.SubFolders mysub SubFolder.Path next end if for each strFolder in arrNewFolders If Not filesys.FolderExists(path & "\" & strFolder) Then filesys.CreateFolder(path & "\" & strFolder) WScript.Echo ("A new folder has been created at: " & path & "\" & strFolder) End If next End Sub |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Script going too deep into subfolders, need help! "Rich" <Rich@xxxxxx> wrote in message news:6F1E60CF-C642-4587-A159-0E9A7AF18960@xxxxxx Quote: > OK, I found the following script, and it does exactly what I want it to > do, > except it creates the subfolder SaveHere in every subfolder. What I want > it > to do, is only create a SaveHere folder inside every folder one level > deeper > than c:\temp. Like in C:\temp\1, C:\temp\2 i want it to create a SaveHere > folder, but not in C:\temp\1\a or c:\temp\1\a\z. I hope that makes > sense. > Can someone help me out? I'm not very good at the whole recursive stuff > yet. > > > > > Dim arrNewFolders > arrNewFolders=Array(_ > "SaveHere") > newfolderpath = "C:\TEMP" > mysub(newfolderpath) > '**********start of recursive Sub routine ************* > Sub mysub(path) > Dim filesys, newfolderpath, RootFolder, FolderColl, SubFolder > wscript.echo "Processing " & path > Set filesys=CreateObject("Scripting.FileSystemObject") > Set RootFolder = filesys.GetFolder(path) > ' Process subfolders > if RootFolder.SubFolders.Count>0 then > For Each SubFolder In RootFolder.SubFolders > mysub SubFolder.Path > next > end if > > for each strFolder in arrNewFolders > If Not filesys.FolderExists(path & "\" & strFolder) Then > filesys.CreateFolder(path & "\" & strFolder) > WScript.Echo ("A new folder has been created at: " & path & "\" & > strFolder) > End If > next > End Sub > ======= Sub mysub(path) Dim filesys, newfolderpath, RootFolder, FolderColl, SubFolder wscript.echo "Processing " & path Set filesys=CreateObject("Scripting.FileSystemObject") Set RootFolder = filesys.GetFolder(path) ' Process subfolders if RootFolder.SubFolders.Count>0 then For Each SubFolder In RootFolder.SubFolders for each strFolder in arrNewFolders If Not filesys.FolderExists(SubFolder.Path & "\" & strFolder) Then filesys.CreateFolder(SubFolder.Path & "\" & strFolder) WScript.Echo ("A new folder has been created at: " _ & SubFolder.Path & "\" & strFolder) End If next next end if End Sub -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Script going too deep into subfolders, need help! "Rich" <Rich@xxxxxx> wrote in message news:6F1E60CF-C642-4587-A159-0E9A7AF18960@xxxxxx Quote: > OK, I found the following script, and it does exactly what I want it to > do, > except it creates the subfolder SaveHere in every subfolder. What I want > it > to do, is only create a SaveHere folder inside every folder one level > deeper > than c:\temp. Like in C:\temp\1, C:\temp\2 i want it to create a SaveHere > folder, but not in C:\temp\1\a or c:\temp\1\a\z. I hope that makes > sense. > Can someone help me out? I'm not very good at the whole recursive stuff > yet. copying some script from somewhere without attempting to understand what it does will rarely give you the desired result. This leads directly to your second problem: You do *not* want a recursive routine, you simple want a routine that enumerates all subfolders of the specified folder, then creates a sub-sub-folder in each of them. Recursive routines will do exactly what your script does: They go as deep as they can. There is a third and minor issue: The name of the folder you're trying to create is a string, not an array. Try this approach: sNewFolder = "\SaveHere" Set oFSO = CreateObject("Scripting.FileSystemObject") Set oFolder = oFSO.GetFolder("C:\TEMP") For Each oSubfolder In oFolder.SubFolders WScript.Echo "Creating " & oSubfolder.Path & sNewFolder ' oFSO.CreateFolder oSubfolder.Path & sNewFolder Next Uncomment the second line from the bottom to activate the script. Note that you must add your own code to check if the folder to be created does not already exist. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Script to remove space in all files in all subfolders | VB Script | |||
| Please help Im in a deep **** with Realtek | Sound & Audio | |||
| Unexpected reboot after deep sleep | Vista General | |||
| How to recover from deep sleep? | Vista General | |||
| Re: World of Warcraft random deep freezes | Vista Games | |||