Sideway BICK BlogSideway BICK BLOG from Sideway

A Sideway to Sideway Home

Link:http://output.to/sideway/default.asp?qno=130300023

File System Manipulation, ASP Server Component, Built-in Function, FileSystemObject Object

FileSystemObject Object

One function of FileSystemObject object is the manipulation of general file system information. One type of the file system manipulation is related to the local system. The other type of the file system manipulation is related to the path string editing and the path string need not be an existing path.

FileSystemObject.GetExtensionName

FileSystemObject.GetExtensionName method is the method to return the string of the file extension of the last component from the specified path related to the specified FileSystemObject Object.

Syntax:

FileSystemObjectName.GetExtensionName(path)

 Or in VBScript. Imply

pathext = FileSystemObjectName.GetExtensionName(path)

 Or in JScript. Imply

pathext = FileSystemObjectName.GetExtensionName(path)

Parameters:

pathext

The parameter "pathext" is the name assigned to the path extension string returned by the method using the FileSystemObjectName.GetExtensionName Method.

FileSystemObjectName

The parameter "FileSystemObjectName" is used to specify the name of the instance of the FileSystemObject Object related to.

path

The parameter "path" is used to specify an existing path to which the path extension to be returned. The "path" is not necessary to specify any existing folder.

Return Values:

path extension string

The method returns a string of the path extension related to the specified FileSystemObject Object. 

Remarks:

FileSystemObjectName should always refer to a FileSystemObject Object.

For network drives, the root directory (\) is considered to be a component.

 The GetExtensionName Method returns an empty string ("") if the file of the last component of the specified path does not exist.

Examples:

  • Example of using the GetExtensionName method to return a path extension string of the last component of the specified path

    ASP VBScript command:

    <script runat="server" language="VBScript">
    Dim fso, pathext
    Set fso = CreateObject("Scripting.FileSystemObject")
    pathext = fso.GetExtensionName("c:")
    Response.Write pathext  & "<br>"
    Response.Write fso.GetExtensionName("d:") & "<br>"
    Response.Write fso.GetExtensionName("c:..") & "<br>"
    Response.Write fso.GetExtensionName("d:..") & "<br>"
    Response.Write fso.GetExtensionName("c:\") & "<br>"
    Response.Write fso.GetExtensionName("d:\") & "<br>"
    Response.Write fso.GetExtensionName("c:*.*\xyz") & "<br>"
    Response.Write fso.GetExtensionName("d:*.*\xyz") & "<br>"
    Response.Write fso.GetExtensionName("c:\..\..\xyz") & "<br>"
    Response.Write fso.GetExtensionName("d:\..\..\xyz") & "<br>"
    Response.Write fso.GetExtensionName("xyz") & "<br>"
    Response.Write fso.GetExtensionName("xyz.xyz") & "<br>"
    Response.Write fso.GetExtensionName("c:\xyz") & "<br>"
    Response.Write fso.GetExtensionName("c:\xyz\xyz") & "<br>"
    Response.Write fso.GetExtensionName("c:\xyz.xyz") & "<br>"
    </script>

    HTML web page ouput:ouput:
    1.  
    2.  
    3.  
    4.  
    5.  
    6.  
    7.  
    8.  
    9.  
    10.  
    11.  
    12. xyz
    13.  
    14.  
    15. xyz
  • Example of using the GetSpecialFolder method to create a new path string

    ASP JScript command:

    <script runat="server" language="JScript">
    var fso, pathext="";
    fso = new ActiveXObject("Scripting.FileSystemObject");
    pathext += fso.GetExtensionName("c:");
    Response.Write("<ol>");
    Response.Write("<li>" + pathext + "</li>");
    Response.Write("<li>" + fso.GetExtensionName("d:") + "</li>");
    Response.Write("<li>" + fso.GetExtensionName("c:..") + "</li>");
    Response.Write("<li>" + fso.GetExtensionName("d:..") + "</li>");
    Response.Write("<li>" + fso.GetExtensionName("c:\\") + "</li>");
    Response.Write("<li>" + fso.GetExtensionName("d:\\") + "</li>");
    Response.Write("<li>" + fso.GetExtensionName("c:*.*\\xyz") + "</li>");
    Response.Write("<li>" + fso.GetExtensionName("d:*.*\\xyz") + "</li>");
    Response.Write("<li>" + fso.GetExtensionName("c:\\..\\..\\xyz") + "</li>");
    Response.Write("<li>" + fso.GetExtensionName("d:\\..\\..\\xyz") + "</li>");
    Response.Write("<li>" + fso.GetExtensionName("xyz") + "</li>");
    Response.Write("<li>" + fso.GetExtensionName("xyz.xyz") + "</li>");
    Response.Write("<li>" + fso.GetExtensionName("c:\\xyz") + "</li>");
    Response.Write("<li>" + fso.GetExtensionName("c:\\xyz\\xyz") + "</li>");
    Response.Write("<li>" + fso.GetExtensionName("c:\\xyz.xyz") + "</li>");
    Response.Write("</ol>");
    </script>

    HTML web page ouput:
    1.  
    2.  
    3.  
    4.  
    5.  
    6.  
    7.  
    8.  
    9.  
    10.  
    11.  
    12. xyz
    13.  
    14.  
    15. xyz

FileSystemObject.GetTempName Method

FileSystemObject.GetTempName method is the method to return a randomly generated temporary name for used as a temporary file or folder name related to the specified FileSystemObject Object.

Syntax:

FileSystemObjectName.GetTempName()

 Or in VBScript. Imply

tname = FileSystemObjectName.GetTempName()

 Or in JScript. Imply

tname = FileSystemObjectName.GetTempName()

Parameters:

tname

The parameter "tname" is the name assigned to the temporary name string randomly generated and returned by the method using the FileSystemObjectName.GetTempName Method.

FileSystemObjectName

The parameter "FileSystemObjectName" is used to specify the name of the instance of the FileSystemObject Object related to.

Return Values:

tname string

The method returns a string of the  randomly generated temporary name related to the specified FileSystemObject Object. 

Remarks:

FileSystemObjectName should always refer to a FileSystemObject Object.

The GetTempName method only returns a randomly generated temporary name for further use. The GetTempName method itself does not create a file or a folder but the randomly generated temporary name can be used as a randomly generated temporary file name or folder name.

Examples:

  • Example of using the GetTempName method to create a randomly generated temporary name

    ASP VBScript command:

    <script runat="server" language="VBScript">
    Dim fso, tname
    Set fso = CreateObject("Scripting.FileSystemObject")
    tname = fso.GetTempName()
    Response.Write tname
    </script>

    HTML web page ouput:

    rad8674C.tmp

  • Example of using the GetTempName method to create a randomly generated temporary name

    ASP JScript command:d:

    <script runat="server" language="JScript">
    var fso, tname;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    tnamet = fso.GetTempName();
    Response.Write(tnamet);
    </script>t;

    HTML web page ouput:

    rad57DF1.tmp

Link:http://output.to/sideway/default.asp?qno=130300024

DriveExists / GetDriveName / GetDrive, FileSystemObject Object, ASP Server Component

FileSystemObject Object

One function of FileSystemObject object is the manipulation of drives of the file system.

FileSystemObject.DriveExists

FileSystemObject.DriveExists method is the method to check whether the specified drive specification exist or not. The DriveExists method returns True if the specified drive exists and the DriveExists method returns False if the specified drive does not exist.

Syntax:

FileSystemObjectName.DriveExists(drivespec)

 Or in VBScript. Imply

driveflag = FileSystemObjectName.DriveExists(drivespec)

 Or in JScript. Imply

driveflag = FileSystemObjectName.DriveExists(drivespec)

Parameters:

driveflag

The parameter "driveflag" is the name assigned to the Boolean value returned by the method using the FileSystemObjectName.DriveExists Method.

FileSystemObjectName

The parameter "FileSystemObjectName" is used to specify the name of the instance of the FileSystemObject Object related to.

drivespec

The parameter "drivespec" is used to specify the drive to be checked. The value of parameter "folderspec" can be a drive letter or a completer drive specification.

Return Values:

Boolean value

The method returns a Boolean value to indicate whether the specified drive exist or not related to the specified FileSystemObject Object. 

Remarks:

FileSystemObjectName should always refer to a FileSystemObject Object.

For drive with removable media, the DriveExists method returns true even if there is no media present. And a removable media can use IsReady property of the Drive object to determine whether the drive is ready.

Examples:

  • Example of using the DriveExists method to check the existence of the specified drive

    ASP VBScript command:

    <script runat="server" language="VBScript">
    Dim fso, driveflag
    Set fso = CreateObject("Scripting.FileSystemObject")
    driveflag = fso.DriveExists("c:")
    Response.Write driveflag  & "<br>"
    Response.Write fso.DriveExists("c")  & "<br>"
    Response.Write fso.DriveExists("c:\")  & "<br>"
    </script>

    HTML web page ouput:ouput:

    True
    True
    True

  • Example of using the DriveExists method to check the existence of the specified drive

    ASP JScript command:

    <script runat="server" language="JScript">
    var fso, driveflag;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    driveflag = fso.DriveExists("c:");
    Response.Write(driveflag + "<br />");
    Response.Write(fso.DriveExists("c") + "<br />");
    Response.Write(fso.DriveExists("c:\\") + "<br />");
    </script>

    HTML web page ouput:

    true
    true
    true

FileSystemObject.GetDriveName Method

FileSystemObject.GetDriveName method is the method to get the name of the drive string from the specified path specification related to the specified FileSystemObject Object.

Syntax:

FileSystemObjectName.GetDriveName(path)

 Or in VBScript. Imply

drvname = FileSystemObjectName.GetDriveName(path)

 Or in JScript. Imply

drvname = FileSystemObjectName.GetDriveName(path)

Parameters:

drvname

The parameter "drvname" is the name assigned to the drive name string returned by the method using the FileSystemObjectName.GetDriveName Method.

FileSystemObjectName

The parameter "FileSystemObjectName" is used to specify the name of the instance of the FileSystemObject Object related to.

Path

The parameter "Path" is used to specify the path specification for the component of which the drive name to be returned.

Return Values:

drvname string

The method returns a string of the  drive name related to the specified FileSystemObject Object. The GetDriveName method returns a zero-length string ("") if the drive can't be determined. The GetDriveName method only returns the drive name on the provided path string neither the conflict on the specified path nor the existence of the specified path will be checked.

Remarks:

FileSystemObjectName Method should always refer to a FileSystemObject Object.

Examples:

  • Example of using the GetDriveName method to return the drive name

    ASP VBScript command:

    <script runat="server" language="VBScript">
    Dim fso, drvname
    Set fso = CreateObject("Scripting.FileSystemObject")
    drvname = fso.GetDriveName("c:\test")
    Response.Write drvname & "<br />"
    Response.Write fso.GetDriveName("test") & "<br />"
    </script>

    HTML web page ouput:

    c:
     

  • Example of using the GetDriveName method to return the drive name

    ASP JScript command:

    <script runat="server" language="JScript">
    var fso, drvname;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    drvname = fso.GetDriveName("c:\test");
    Response.Write(drvname+"<br \>");
    Response.Write(fso.GetDriveName("test")+"<br \>");
    </script>

    HTML web page ouput:age ouput:

    c:
     

FileSystemObject.GetDrive Method

FileSystemObject.GetDrive method is the method to return an instance of a Drive object corresponding to the specified drive specification related to the specified FileSystemObject Object.

Syntax:

FileSystemObjectName.GetDrive(drivespec)

 Or in VBScript. Imply

DriveObjectName = FileSystemObjectName.GetDrive(drivespec)

 Or in JScript. Imply

DriveObjectName = FileSystemObjectName.GetDrive(drivespec)

Parameters:

DriveObjectName

The parameter "DriveObjectName" is the name assigned to the Drive object returned by the method using the FileSystemObjectName.GetDrive Method.

FileSystemObjectName

The parameter "FileSystemObjectName" is used to specify the name of the instance of the FileSystemObject Object related to.

drivespec

The parameter "drivespec" is used to specify the drive specification for the Drive object to be returned. The parameter drivespec can be a drive letter (c), a drive letter with a colon appended (c:), a drive letter with a colon and path separator appended (c:\), or any network share specification (\\computera\share\). Unlike the return of drive name, an error occurs if the parameter drivespec does not conform to one of the accepted forms or does not exist. For network shares, a check is made to ensure that the share exists.

Return Values:

Drive object

The method returns an instance of Drive object corresponding to the specified drivespec related to the specified FileSystemObject Object. 

Remarks:

FileSystemObjectName should always refer to a FileSystemObject Object.

A normal path string for the drivespec of GetDrive method can be obtained by using a sequence of Methods on an existing path:

drivespec = fso.GetDriveName(fso.GetAbsolutePathName(path))

Examples:

  • Example of using the GetDrive method to return an instance of Drive object

    ASP VBScript command:

    <script runat="server" language="VBScript">
    Dim fso, DriveObjectName
    Set fso = CreateObject("Scripting.FileSystemObject")
    set DriveObjectName = fso.GetDrive("c")
    Response.Write DriveObjectName.DriveLetter & "<br />"
    set DriveObjectName = fso.GetDrive(fso.GetDriveName(fso.GetAbsolutePathName("test")))
    Response.Write DriveObjectName.DriveLetter & "<br />"
    </script>

    HTML web page ouput:

    C
    C

  • Example of using the GetDrive method to return an instance of Drive object

    ASP JScript command:

    <script runat="server" language="JScript">
    var fso, DriveObjectName;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    DriveObjectName = fso.GetDrive("c");
    Response.Write (DriveObjectName.DriveLetter + "<br />");
    DriveObjectName = fso.GetDrive(fso.GetDriveName(fso.GetAbsolutePathName("test")));
    Response.Write (DriveObjectName.DriveLetter + "<br />");
    </script>

    HTML web page ouput:

    C
    C

Previous Month  MAR  2013  Next Month
SMTWTFS
12
3456789
10111213141516
17181920212223
24252627282930
31

Previous Month  MAR  2012  Next Month
SMTWTFS
123
45678910
11121314151617
18192021222324
25262728293031

Sideway BICK Blog

19/03


Copyright © 2000-2020 Sideway . All rights reserved Disclaimerslast modified on 26 January 2013