JavaScript Tutorial/MS JScript/Folder — различия между версиями

Материал из Web эксперт
Перейти к: навигация, поиск
 
м (1 версия)
 
(нет различий)

Текущая версия на 08:24, 26 мая 2010

Folder

The Folder object provides access to all the properties of a folder.

This object is created by the FileSystemObject.GetFolder().

The folder passed is the name the folder for which you want to create a JScript object.

Method/Property Description Copy() Copies the folder from one location to another Delete() Deletes the specified folder Move() Moves the specified folder Attributes Sets or returns the file system attributes of the folder DateCreated Returns the date the folder was created DateLastAccessed Returns the date the folder was last accessed DateLastModified Returns the date the folder was last modified Drive Returns the drive on which the folder is located Files Returns a Files collection containing all the File objects in the folder IsRootFolder Returns true if the folder is the root folder, false otherwise Name Sets or returns the name of the folder ParentFolder Returns a folder object for the parent folder of the folder Path Returns the path to the folder ShortName Returns the 8.3 version of the name of the folder ShortPath Returns the 8.3 version of the path to the folder Size Returns the byte size of all the contents of the folder SubFolders Returns a Folders collection of all the folders contained in the folder Type Returns the type of folder



<html>
    <script language="JScript1.1">
    <!--
    var myFileSysObj = new ActiveXObject("Scripting.FileSystemObject");
    var myFolder = myFileSysObj.GetFolder("\\temp");
    document.write(myFolder.Drive);
    -->
    </script>
</html>


Folder.Attributes

Syntax



folder.Attributes
    folder.Attributes = attrib


The Attributes property sets or retrieves the attributes of a folder. The following table has the values of the attributes.

Value Stands For Description 0 Normal Normal folder with no attributes set 1 Read Only Read-only folder with read/write attribute 2 Hidden Hidden folder with read/write attribute 4 System System folder with read/write attribute 8 Volume Disk drive volume label with read-only attribute 16 Directory Folder or directory with read-only attribute 32 Archive Folder has changed since last backup with read/write attribute 64 Alias Link or shortcut to a folder with read-only attribute 128 Compressed Compressed folder with read-only attribute

Folder.Copy()

Syntax



folder.Copy(destination)
    folder.Copy(destination, boolean)


Folder.DateCreated

The DateCreated property gets the date when the folder was created.



<html>
    <body>
    <script language="JScript">
    <!--
    function get(){
      var myObject = new ActiveXObject("Scripting.FileSystemObject");
      var myFolder = myObject.GetFolder("c:\\Temp");
      alert (myFolder.DateCreated);
    }
    // End hide-->
    </script>
    Get the date the c:\temp folder was created.
    <form name="myForm">
    <input type="Button" value="Get Date" onClick="get()">
    </form>
    </body>
    </html>


Folder.DateLastAccessed

The DateLastAccessed property gets the date the folder was last accessed.



<html>
    <body>
    <script language="JScript">
    <!--
    function get(){
      var myObject = new ActiveXObject("Scripting.FileSystemObject");
      var myFolder = myObject.GetFolder("c:\\Temp");
      alert (myFolder.DateLastAccessed);
    }
    // End hide-->
    </script>
    Get the date the c:\temp folder was last accessed.
    <form name="myForm">
    <input type="Button" value="Get Last Access" onClick="get()">
    </form>
    </body>
    </html>


Folder.DateLastModified

The DateLastModified property gets the date the folder was last modified.



<html>
    <body>
    <script language="JScript">
    <!--
    function get(){
      var myObject = new ActiveXObject("Scripting.FileSystemObject");
      var myFolder = myObject.GetFolder("c:\\Temp");
      alert (myFolder.DateLastModified);
    }
    // End hide-->
    </script>
    Get the date the c:\temp folder was last modified.
    <form name="myForm">
    <input type="Button" value="Get Last Modified" onClick="get()">
    </form>
    </body>
    </html>


Folder.Delete()

Syntax



folder.Delete(boolean)
    folder.Delete()


Folder.Drive

The Drive property returns the drive letter of the folder.



<html>
    <body>
    <script language="JScript">
    <!--
    function get(){
      var myObject = new ActiveXObject("Scripting.FileSystemObject");
      var myFolder = myObject.GetFolder("c:\\Temp");
      alert (myFolder.Drive);
    }
    // End hide-->
    </script>
    Get the drive the c:\temp folder is located on.
    <form name="myForm">
    <input type="Button" value="Get Drive" onClick="get()">
    </form>
    </body>
    </html>


Folder.Files

The Files property returns a collection consisting of all the File objects contained in the folder. This includes hidden and system files.



<html>
    <script language="JScript1.1">
    <!--
    var myFileSysObj = new ActiveXObject("Scripting.FileSystemObject");
    var myFolder = myFileSysObj.GetFolder("\\temp");
    var myEnum = new Enumerator(myFolder.Files);
    while(!myEnum.atEnd()){
      document.write(myEnum.item() + "<br>");
      myEnum.moveNext();
    }
    -->
    </script>
</html>


Folder.IsRootFolder

The IsRootFolder property evaluates to true if the folder is the root folder, and false otherwise.



<html>
    <script language="JScript1.1">
    <!--
    var myFileSysObj = new ActiveXObject("Scripting.FileSystemObject");
    var myFolder = myFileSysObj.GetFolder("\\temp");
    if(myFolder.IsRootFolder){
      document.write(myFolder.Name + " is the root folder.");
    }else{
      document.write(myFolder.Name + " is not the root folder.");
    }
    -->
    </script>
</html>


Folder.Move()

Syntax



folder.Move(destination)


Folder.Name

The Name property sets or gets the name of the folder.



<html>
    <body>
    <script language="JScript">
    <!--
    function get(){
      var myObject = new ActiveXObject("Scripting.FileSystemObject");
      var myFolder = myObject.GetFolder("c:\\Temp");
      alert (myFolder.Name);
    }
    // End hide-->
    </script>
    Get the name of the c:\temp folder.
    <form name="myForm">
    <input type="Button" value="Get Name" onClick="get()">
    </form>
    </body>
    </html>


Folder.ParentFolder

The ParentFolder property returns a new Folder object for the parent folder.



<html>
    <body>
    <script language="JScript">
    <!--
    function get(){
      var myObject = new ActiveXObject("Scripting.FileSystemObject");
      var myFolder = myObject.GetFolder("c:\\Temp");
      alert (myFolder.ParentFolder.Path);
    }
    // End hide-->
    </script>
    Get the name of the c:\temp parent folder.
    <form name="myForm">
    <input type="Button" value="Get Parent Folder" onClick="get()">
    </form>
    </body>
    </html>


Folder.Path

The Path property returns the full path to the folder.



<html>
    <body>
    <script language="JavaScript1.2">
    <!--
    function get(){
      var myObject = new ActiveXObject("Scripting.FileSystemObject");
      var myFolder = myObject.GetFolder("c:\\Temp");
      alert (myFolder.Path);
    }
    // End hide-->
    </script>
    Get the path of the c:\temp folder.
    <form name="myForm">
    <input type="Button" value="Get Path" onClick="get()">
    </form>
    </body>
    </html>


Folder.ShortName

The ShortName property returns the 8.3 name of the folder.
    <html>
    <body>
    <script language="JScript">
    <!--
    function get(){
      var myObject = new ActiveXObject("Scripting.FileSystemObject");
      var myFolder = myObject.GetFolder("c:\\Program Files");
      alert (myFolder.ShortName);
    }
    // End hide-->
    </script>
    Get the short name of the "C:\Program Files" folder.
    <form name="myForm">
    <input type="Button" value="Get Short Name" onClick="get()">
    </form>
    </body>
    </html>


Folder.ShortPath

The ShortPath property returns the 8.3 path to the folder.



<html>
    <body>
    <script language="JScript">
    <!--
    function get(){
      var myObject = new ActiveXObject("Scripting.FileSystemObject");
      var myFolder = myObject.GetFolder("c:\\Program Files");
      alert (myFolder.ShortPath);
    }
    // End hide-->
    </script>
    Get the short path of the "c:\\Program Files" folder.
    <form name="myForm">
    <input type="Button" value="Get Short Path" onClick="get()">
    </form>
    </body>
    </html>


Folder.Size

The Size property returns the byte size of the folder.



<html>
    <body>
    <script language="JScript">
    <!--
    function get(){
      var myObject = new ActiveXObject("Scripting.FileSystemObject");
      var myFolder = myObject.GetFolder("c:\\Program Files");
      alert (myFolder.Size);
    }
    // End hide-->
    </script>
    Get the size of the "c:\\Program Files" folder.
    <form name="myForm">
    <input type="Button" value="Get Size" onClick="get()">
    </form>
    </body>
    </html>


Folder.SubFolders

The SubFolders property returns a collection consisting of all the Folder objects contained in the folder. This includes hidden and system folders.



<html>
    <script language="JScript">
    <!--
    var myFileSysObj = new ActiveXObject("Scripting.FileSystemObject");
    var myFolder = myFileSysObj.GetFolder("\\temp");
    var myEnum = new Enumerator(myFolder.SubFolders);
    while(!myEnum.atEnd()){
      document.write(myEnum.item() + "<br>");
      myEnum.moveNext();
    }
    -->
    </script>
</html>


Folder.Type

The Type property returns the type of the folder. For a folder, the return value is File Folder.



<html>
    <body>
    <script language="JScript">
    <!--
    function get(){
      var myObject = new ActiveXObject("Scripting.FileSystemObject");
      var myFolder = myObject.GetFolder("c:\\Program Files");
      alert (myFolder.Type);
    }
    // End hide-->
    </script>
    Get the type of the "c:\\Program Files" folder.
    <form name="myForm">
    <input type="Button" value="Get Type" onClick="get()">
    </form>
    </body>
    </html>