本帖最后由 arthur 于 2012-8-25 18:15 编辑
Using the FSO (File System Object) in VB6Level:
The File System Object (FSO) object model provides an object-based tool for working with folders and files. Using "object.method" syntax, it exposes a comprehensive set of properties and methods to perform file system operations such as creating, moving, deleting, and providing information about folders and files. The FSO also provides methods for reading and writing sequential text files, however it does NOT have methods for processing binary or random files. The FSO is (or should be) used primarily with VBScript. VBScript is a scripting language used with ASP for web development; VBScript is also used for Windows scripting. (Windows scripting files, which have a ".vbs" extension, can be thought of as a modern-day replacement for the MS-DOS "BAT" files used in the days of yore). VBScript is a pared-down version of Visual Basic, and as such does not have all of the functionality of "VB proper". One of the things missing in VBScript is the set of native VB file processing statements and functions discussed in the last several topics – so in VBScript, the FSO must be used to manipulate files and folders. However, VB proper can make use of the FSO in addition to its native file processing commands. There are some trade-offs in using the FSO with Visual Basic. On the one hand, the FSO can make certain tasks easier to program with smoother and less arcane syntax than the native VB statements. On the other hand, using the FSO requires adding an additional dependancy to your project, it is slower, it does not support the reading or writing of random and binary files, and it can be disabled by system administrators concerned about security. To use the FSO with your VB project, you must add a reference to "Microsoft Scripting Runtime" (which is the system file "SCRRUN.DLL"). To do this, from the VB IDE, first go to the Project menu, and select References, as shown below: 
From the References dialog box, check Microsoft Scripting Runtime, as shown below, and click OK. 
Once you have done the above, you can use the FSO in your VB project. In your code, you must declare an object variable for the FSO and instantiate it. The most concise way of doing this is use the "New" keyword in your declaration, as shown below. (Note: The "Scripting." qualifier is optional here.) Dim objFSO As New Scripting.FileSystemObject An alternative way of doing this is to declare the FSO variable without the "New" keyword and instantiate it later with the "Set" statement, as shown below. (Note: Again, the "Scripting." qualifier is optional.) Dim objFSO As Scripting.FileSystemObject ... Set objFSO = New Scripting.FileSystemObject You can also use "late binding" by declaring the FSO variable as a generic "object" and then using the "CreateObject" method to instantiate it later, as shown below. This is the slowest method, but it is the way it must be done in VBScript. The "Scripting." qualifier is required here. Dim objFSO As Object ... Set objFSO = CreateObject("Scripting.FileSystemObject") The tables below show the various objects, properties, and methods available with the FSO.
http://www.vb6.us/tutorials/using-fso-file-system-object-vb6 |