Solved

Script or Batch to Create New Folders within Folders Automatically on File Server

Posted on 2009-05-06
16
601 Views
Last Modified: 2013-12-02
First off, not too familar with scripting, just basic batch files to map network drives.

I need a script or batch, or some automated way to create 3 folders called: Individual, Group, Family.

These folders need to be placed in an already existing folder, called: Clinical Progress Notes.

The Clinical Progress Notes folder is located in various different folders and directories on our file server. For example: it can be in
\\fileserver\company\Dir1\Location\Person\Clinical Progress Notes
or it can be  in
\\fileserver\company\Dir78\Location21\Person\Clinical Progress notes

etc...
The only thing that stays the same is \\filerserver\company  any following directories can change.

So something along the lines of 'If Clinical Progress Notes Folder exists, then create folders Individual, Group, and Family" and "if the 3 folders already exist, then ignore" (so I dont want any conflicts with the folders if they already exist.

Thanks
0
Comment
Question by:fireguy1125
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
16 Comments
 
LVL 10

Accepted Solution

by:
TakedaT earned 500 total points
ID: 24318899
Give this a go.  Just change the strSource path on the second line to the actual path.
dim objFSO : set objFSO = CreateObject("Scripting.FileSystemObject")
dim strSource : strSource = "\\fileserver\company\"
dim strFolderName : strFolderName = "Clinical Progress Notes"
dim arrFolders(2)
arrFolders(0) = "Individual" : arrFolders(1) = "Group" : arrFolders(2) = "Family"
Set objDir = objFSO.GetFolder(strSource)
 
If not objFSO.FolderExists(strSource) then
	MsgBox "Source folder does not exist"
	wscript.quit
End If
SearchDir objDir,strFolderName
'For x=0 to 2
	'strCopyFrom = ""
	'SearchDir objDir,arrFolders(x)
	'If strCopyFrom <> "" then
	'	objFSO.CopyFile strCopyFrom,strDest
	'End If
'Next
Function SearchDir(strCurrentDir,strFolderName)
	For Each folder In strCurrentDir.SubFolders
		strCurDir =	mid(folder,instrrev(folder,"\")+1)
		If strCurDir = strFolderName then
			For i=0 to 2
				If not objFSO.FolderExists(folder&"\"&arrFolders(i)) then
					objFSO.CreateFolder(folder&"\"&arrFolders(i))
				End If
			Next
		End If
		SearchDir folder,strFolderName
	Next
End Function

Open in new window

0
 
LVL 10

Expert Comment

by:TakedaT
ID: 24318907
It is a .vbs script BTW.
0
 
LVL 1

Author Comment

by:fireguy1125
ID: 24319428
ok, i saved it as foldercreatescript.vbs on the desktop of the file server.  double clicked it, and nothing.  looking at cpu usage though it's up there with things like lsass.exe, system.exe, services.exe and wscript.exe using the bulk of it.  i'm assuming this means it's running and it's going to take a while, since it has to do this to around 2,000 folders?
0
Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

 
LVL 10

Expert Comment

by:TakedaT
ID: 24319462
It may take a minute or two.  But that should be it.  Its only creating folders.  Did you make sure to give it a valid path in line 2?
0
 
LVL 1

Author Comment

by:fireguy1125
ID: 24319579
Yes, it still looks like it's running.  I made the appropriate change to the initial top folder as \\fileserver\company\share (with our actual path name)

of couse beneith that are several folders in the share folder, and several folders in those folders, then several more folders, until it actually reaches the Clinical Progress Notes Folder, since the location of the Clinical Progress Notes folder can be in thousands of other folders (peoples names and different locations)
0
 
LVL 10

Expert Comment

by:TakedaT
ID: 24319659
It would run much quicker if it was ran from the local machine where these folders are, but it should still work nonetheless.  Looking through a few thousand folders accross the network may take some time.  I initially forgot that it was a networked server when I said only a few minutes.

Also, I forgot to delete lines 13 to 19.  They are commented out anyway so they wont hurt, but you can replace them with :

MsgBox "Done"

to let you know when it is finished.
0
 
LVL 1

Author Comment

by:fireguy1125
ID: 24325230
Ok it worked! CPU back to normal today, and folders are created everywhere.  However, I ran into a little problem, i'm sure you can assist me with as well.  I had the script run in a section of folders that is no longer used (only for archive purposes), so the folders weren't necessary to create there.  No big deal, but that's probably why it took a lot longer.  Any way to get a script to delete the 3 folders only from the directory: \\fileserver\company\share\old\2008 and going back to 2004 same path. if you want me to open up new question i can do that.
0
 
LVL 10

Expert Comment

by:TakedaT
ID: 24325322
I can write that for you.  But it will delete ALL folders with those folder names, even those that were there before that script run yesterday.
0
 
LVL 1

Author Comment

by:fireguy1125
ID: 24325379
That should be fine then, as long as I put the strSource to the subdirectory that the folders shouldn't be in correct?  As long as I put it in \\fileserver\company\share\old\2008 then run it in \\fileserver\company\share\old\2007 and so on.  This shouldn't delete anything before that folder? Which we created with the previous script, which was applied to \\fileserver\company\share.
0
 
LVL 10

Expert Comment

by:TakedaT
ID: 24325415
Yup...the search will begin at the strSource folder, nothing above is touched.  But, I can also have it check to make sure the folders are empty if you would like.  Sound good?
0
 
LVL 1

Author Comment

by:fireguy1125
ID: 24325443
Sure sounds great!
0
 
LVL 10

Expert Comment

by:TakedaT
ID: 24325463
OK..Just give me a little while.  I have some work to do here first.
0
 
LVL 10

Expert Comment

by:TakedaT
ID: 24325803
Try this.
dim objFSO : set objFSO = CreateObject("Scripting.FileSystemObject")
dim strSource : strSource = "D:\test\New Folder"'"\\fileserver\company\share\old\2008"
dim strFolderName : strFolderName = "Clinical Progress Notes"
dim arrFolders(2)
arrFolders(0) = "Individual" : arrFolders(1) = "Group" : arrFolders(2) = "Family"
Set objDir = objFSO.GetFolder(strSource)
 
If not objFSO.FolderExists(strSource) then
        MsgBox "Source folder does not exist"
        wscript.quit
End If
SearchDir objDir,strFolderName
MsgBox "Done"
Function SearchDir(strCurrentDir,strFolderName)
        For Each folder In strCurrentDir.SubFolders
			strCurDir = mid(folder,instrrev(folder,"\")+1)
			strParentDir = mid(replace(folder,"\"&strCurDir,""),instrrev(replace(folder,"\"&strCurDir,""),"\")+1)'mid(folder,instrrev(folder,"\")+1)
	        For i=0 to 2
	        	If strCurDir = arrFolders(i) and strParentDir = strFolderName then
	        		If CheckForFiles(folder) = False then
	        			objFSO.DeleteFolder(folder)
	        		End If
	        	End If
	        Next
        Next
        For Each folder In strCurrentDir.SubFolders
        	SearchDir folder,strFolderName
        Next
End Function
Function CheckForFiles(dir)
	CheckForFiles = False
	dim objDir2 : set objDir2 = objFSO.GetFolder(dir)
	For Each file2 In objDir2.Files
		CheckForFiles=True
	Next
End Function

Open in new window

0
 
LVL 1

Author Comment

by:fireguy1125
ID: 24325966
thanks, line 2 has 2 different sources? what's the "d:\test\new folder" for?
0
 
LVL 10

Expert Comment

by:TakedaT
ID: 24326633
Sorry, had to run to a meeting.  The second one is commented out with the'.  It was just for when I was testing.  You can delete both and put in what you need in quotes.
0
 
LVL 1

Author Comment

by:fireguy1125
ID: 24326687
Works like a charm! Thanks for all your help!
0

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If, like me, you have a lot of Dell servers in the estate you manage this article should save you a little time. When attempting to login to iDrac on any server I would be presented with two errors. The first reads "Do you want to run this applicati…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question