Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!:File Management
function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg) {
var end = document.cookie.indexOf (";", j);
if (end == -1)
end = document.cookie.length;
return unescape(document.cookie.substring(j, end));
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
var m1='';
var gifstr=GetCookie("UsrType");
if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; }
document.write(m1+m2+m3);
Keyword
Title
Author
ISBN
Publisher
Imprint
Brief
Full
Advanced Search
Search Tips
Please Select
-----------
Components
Content Mgt
Certification
Databases
Enterprise Mgt
Fun/Games
Groupware
Hardware
IBM Redbooks
Intranet Dev
Middleware
Multimedia
Networks
OS
Prod Apps
Programming
Security
UI
Web Services
Webmaster
Y2K
-----------
New Titles
-----------
Free Archive
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
(Publisher: The Coriolis Group)
Author(s): Peter G. Aitken
ISBN: 1576102815
Publication Date: 08/01/98
function isIE4()
{
return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') );
}
function bookMarkit()
{
var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0";
parent.location.href=url;
//var win = window.open(url,"myitk");
//if(!isIE4())
// win.focus();
}
Search this book:
Previous
Table of Contents
Next
We can write a simple program to demonstrate how you can use the Drives collection to obtain information about the drives on the system. Create a Standard EXE project and place a Text Box on the form. Set the Text Boxs Multiline and Locked properties to True and set its size to nearly fill the form. Put the code from Listing 14.1 in the Text Boxs Click event procedure. When you run the program, click on the Text Box. After a brief pause it will display a list of the systems drives and their total and free space. This is shown in Figure 14.1. I named this program DRIVESDEMO.
Listing 14.1 Demonstrating the Drives collection.
Private Sub Text1_Click()
Dim fs, d, dc
Dim msg As String
Set fs = CreateObject(Scripting.FileSystemObject)
Set dc = fs.Drives
For Each d In dc
msg = msg & Drive & d.Path
If Not d.IsReady Then
msg = msg & is not ready. & vbCrLf
Else
msg = msg & vbCrLf & Space(5)
msg = msg & Total space: & FormatNumber(d.TotalSize)
msg = msg & vbCrLf & Space(5)
msg = msg & Free space: & FormatNumber(d.FreeSpace)
msg = msg & vbCrLf
End If
Next
Text1.Text = msg
End Sub
The Folder Object
A Folder object represents a single folder, or subdirectory, on a drive. You use the objects methods to copy, move, or delete the folder (as explained later) and the objects properties to obtain information about the folder. Perhaps most important, a Folder object contains two collections, Files and SubFolders, that provide access to the files and subfolders within the folder. Table 14.3 explains the properties of the Folder object.
Because each Folder object contains information about its parent folder and its subfolders, you can easily traverse the entire folder structure on a drive. This is a powerful tool, as will be demonstrated later. First, however, we need to look at the Folder objects methods.
The Copy method copies the folder and its contents to a new location. The syntax is (assuming f to be a Folder object)
f.Copy destination[, overwrite]
where destination specifies the destination where the folder is to be copied. Set overwrite to True (the default) to overwrite existing files or folders, or to False otherwise. Note that you can also copy a folder using the FileSystemObjects CopyFolder method.
The Move method moves the folder and its contents from one location to another. The syntax is
f.Move destination
where destination specifies the destination where the folder is to be moved. You can also move folders with the FileSystemObjects MoveFolder method.
Figure 14.1 Using the Drives collection to obtain information about the systems drives.
Table 14.3 Properties of the Folder object.
Property
Description
DateCreated
Date and time the folder was created.
DateLastAccessed
Date and time the folder was last accessed.
DateLastModified
Date and time the folder was last modified.
Drive
Drive letter of the drive where the folder resides.
Files
A Files collection containing all the files in the folder.
IsRootFolder
True if the folder is the root, False otherwise.
Name
Sets or returns the name of the folder.
ParentFolder
Returns a Folder object representing the folders parent folder.
Path
The path of the folder, including the drive letter.
ShortName
The short name used by programs that require the old 8.3 style naming convention.
ShortPath
The short path used by programs that require the old 8.3 style naming convention.
Size
The size, in bytes, of all files and subfolders contained in the folder.
SubFolders
A Folders collection containing one Folder object for each subfolder.
The Delete method deletes a folder and its contents. The syntax is:
f.Delete [force]
The optional force argument specifies whether files or folders with the read-only attribute are to be deleted (force = True) or not (force = False, the default). You can also delete folders with the FileSystemObjects DeleteFolder method.
A Folder Demonstration
To demonstrate the power of the Folder object, I have created a small utility that counts the total number of files and folders on your C: drive. This might seem like a difficult task, but as youll see, it requires relatively little code. Figure 14.2 shows the program in operation.
The ease with which we can write this program is a result of two things: the design of the Folder object and the use of a recursive algorithm. Heres an outline of how it works:
1. Get the drives root Folder object.
2. Use the root folders Folders collection to access each of its subfolders.
Figure 14.2 The FOLDERDEMO program.
3. Determine the number of files and subfolders in each subfolder and add these values to the totals.
4. Use the subfolders Folders collection to access each of its subfolders.
5. Continue until all subfolders have been processed.
Previous
Table of Contents
Next
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.
Wyszukiwarka
Podobne podstrony:
W5 14 03Plakat JELENIA GORA Przyjazdy wazny od 13 12 15 do 14 03 0814 03Geodezja wykład 3 odwzorowania kartograficzne (14 03 2011)14 03 (formularze)14 03 S1 W ChemiaBud nowaPlakat WROCLAW GL Odjazdy wazny od 13 12 15 do 14 03 08ćwiczenia logorytmiczne 2(14 03)14,03,2010 SQL14 03 Maszyny do robot pomocniczych i wykonczeniowych14 03 (drugi formularz)pedagogika24 03 14więcej podobnych podstron