An Introduction to Files and Folders in WSH - Using What You’ve Learned
(Page 5 of 5 )
In part two of this series we’ll take a look at some of the more advanced methods and properties that the FileSystemObject has to offer. In the meantime, play around with this a bit.
You’ll begin to see that every task for which you write code can be accomplished in two or three other ways. That goes to show the flexibility that VBScript and WSH have.
I’m sure someone at this point is wondering how to rename files and folders, right? I’ve shown you all of the basic file operations except that. Well, here’s why. Think about what a rename really is.
At the file or folder level, the computer must make a copy of the original file with a new name and then delete the first. There is no need to have another method for this when we can perform the same procedure with the ones we have.
The simplest way to perform a file (or folder) rename is to use the corresponding move method. Just supply the new filename for the destination. Here’s a quick example of how to rename C:text1.txt into C:text2.txt
Set objFso = CreateObject("Scripting.FileSystemObject")
objFso.MoveFile "C:text1.txt", "C:text2.txt"
Believe me when I tell you that we’ve barely scratched the surface. Stick around for part two of this series and learn some of the cool tricks that the FileSystemObject can do. You won’t want to miss it. Until next time, keep coding!
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |