What you can't do
August 14, 2000
The FSO does have some weaknesses - for instance, it stumbles on
binary files. This includes MS Word documents, many image formats,
and, unfortunately, a lot of other files. You can still, however
otherwise manipulate these files - move them, delete them, etc. What
you can't do is open, read, or write to them. Given some ingenuity,
a method could be devised to use the FSO to play with binary files,
but many will find it easier to simply use the old Open method
(check out
MSDN for an example).
Another limitation is file size. When you read or write a lot of
content at once, all the information is stored in memory - and the
larger your content, the larger the memory usage. This tends to slow
everything down, so if you need to manipulate really large files,
or a ton of smaller files, consider breaking the files down into
smaller pieces and clearing the memory often (setting your variables
equal to NULL or "", and releasing your objects ASAP). Moving your
application into a COM object would also tremendously speed up the process.
You also can't manage permissions and file and folder attributes
with the FSO. A great way to implement security would be to create
the guestbook file we described earlier as read-only, and then change
the attribute to writeable only when we need it, and immediately
change it back. This method is often used in
CGI and
Perl scripts,
but unfortunately, there's no pleasant way to do this with the FSO.
What else can I do?
There are a lot of really cool features in the FSO model that most people
aren't aware of. These are the type of features that you normally find
out about after you did things the hard way, and you end up
saying "If only I knew that before!"
I'll briefly list the not-so-common but cool functions here.
|
Little Known FSO Features |
|
GetSpecialFolder Method |
Returns the path to a special
Windows folder: the Windows installation folder; the system folder;
and the Windows Temporary folder. Syntax: FSO.GetSpecialFolder([0, 1, or 2])
|
|
GetTempName Method |
Returns a randomly generated temporary
file or folder name. Useful when you need to store temporary
data (i.e. when you run into the file size limitation described
above). |
|
GetAbsolutePathName Method |
Returns the absolute path of a folder (similar
to Server.MapPath). For example, FSO.GetAbsolutePathName("region") will
return something like "c:\mydocs\myfolder\region" |
|
GetExtensionName Method |
Returns the extension for the last item
in a path (i.e. FSO.GetExtensionName("c:\docs\test.txt") will
return txt) |
|
GetBaseName and GetParentFolder Methods |
Returns the base and parent folder name
respectively of last item in a path (i.e. FSO.GetParentFolder
("c:\docs\mydocs")
will return 'docs') |
|
Drives Property |
Returns a collection of all the drive
objects available on the local machine. This is helpful if you
ever want to build an explorer type interface. |
You'll want to make sure you build in robust error handling routines
though, because some of these above functions will return nasty
errors if the specified file or folder does not exist.
Content Management with the FSO
The wonders of the File System Object
Conclusion
|