Monday, December 3, 2007

The power of scripts


Today, i've got a strange(???) problem, like i have to make a new repository in our backup server, which should looks exactly like another folder tree in same machine, but my requirement is more specific, i don't want to copy the entire folder structure including its sub folders, i.e i need only the top level folders. At first i thought to write a C program for that, but it may take a few hours to write and test. so i decided to experiment with some VBscript. as i am using it for first time, i felt an odd feeling by seeing its syntax. but truly said, its the most powerful stuff for doing such kind of tasks. see my first ever script - to copy the top level folder structure of a repository.


' Get the source folder, subfolders

'create the folder structure in destination as in the src folder
'No subfolders support
'Authour : renjith.sreeATgmail.com
'

Set objFSO = CreateObject("Scripting.FileSystemObject")
set objShell = CreateObject("Shell.Application")

srcFolderPath = InputBox("Enter the source folder","Select a folder","", 100, 100)

If srcFolderPath = "" Then
WScript.Echo "Invalid source folder, quiting..."
WScript.Quit()
End If

destFolderPath = InputBox("Enter the destination folder","Select a folder","", 100, 100)

If destFolderPath = "" Then
WScript.Echo "Invalid destination folder, quiting..."
WScript.Quit()
End If

' dest folder

set destFolder = objShell.NameSpace(destFolderPath)

Set srcFolder = objFSO.GetFolder(srcFolderPath)
Set colSubfolders = srcFolder.Subfolders

For Each objSubfolder in colSubfolders
destFolder.NewFolder (objSubfolder.Name)
Next

WScript.Echo "Folder creation completed."



No comments: