Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 620
  • Last Modified:

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

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
fireguy1125
Asked:
fireguy1125
  • 9
  • 7
1 Solution
 
TakedaTCommented:
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
 
TakedaTCommented:
It is a .vbs script BTW.
0
 
fireguy1125Author Commented:
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
TakedaTCommented:
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
 
fireguy1125Author Commented:
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
 
TakedaTCommented:
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
 
fireguy1125Author Commented:
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
 
TakedaTCommented:
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
 
fireguy1125Author Commented:
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
 
TakedaTCommented:
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
 
fireguy1125Author Commented:
Sure sounds great!
0
 
TakedaTCommented:
OK..Just give me a little while.  I have some work to do here first.
0
 
TakedaTCommented:
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
 
fireguy1125Author Commented:
thanks, line 2 has 2 different sources? what's the "d:\test\new folder" for?
0
 
TakedaTCommented:
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
 
fireguy1125Author Commented:
Works like a charm! Thanks for all your help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 9
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now