An Introduction to Files and Folders in WSH
(Page 1 of 5 )
In this series of articles we’ll take a close look at dealing with files and folders in WSH. There are a few different ways to do this. First we’re going to take a look at WSH’s native way of doing this by using the FileSystemObject.
The FilesSystemObject is VBScript’s way of working directly with the file system. It provides methods and properties for handling and manipulating files and folders. You can create, move, and delete files and folders as well as check and change some attributes.
You should already be familiar with connecting to the FileSystemObject. In VBScript it looks like this:
Set objFso = CreateObject("Scripting.FileSystemObject")
The above code uses the Wscript object’s CreateObject method to get a handle on the FileSystemObject. The beauty of the FileSystemObject is that the ActiveX control can automatically detect the type of file system and work with it. The FileSystemObject can work with any file system supported on your system.
The FileSystemObject works with the native drivers to control the file system. That means if you were to add support for some non-Windows file system such as ext3, then the FileSystemObject would support it inherently.
Keep in mind when creating scripts that deal with the file system, sometimes these processes can take a while. It’s not unusual to take up to 10 minutes or more to enumerate the files and folders on a typical drive that is near capacity. Of course, there are a lot of factors that play into this: drive seek speed, bus speed, processor speed, available memory, and background processes just to name a few. Some files systems are faster than others simply by design.
In short, a little error-handling and some pre-design thought can go a long way.
Before diving into your script, you should also take a couple other things into consideration. Will your script be running locally or remotely? And will you be using this script on multiple hosts or always running it from the same location? These things can affect the way that you handle folder paths. We’ll deal more with these later.
Next: Enumerating Files and Folders >>
More Windows Scripting Articles
More By Nilpo/Developer Shed Staff Writer