Sideway BICK BlogSideway BICK BLOG from Sideway

A Sideway to Sideway Home

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

FolderExists / GetParentFolderName / GetFolder, FileSystemObject Object, ASP Server Component

FileSystemObject Object

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

FileSystemObject.FolderExists

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

Syntax:

FileSystemObjectName.FolderExists(folderspec)

 Or in VBScript. Imply

folderflag = FileSystemObjectName.FolderExists(folderspec)

 Or in JScript. Imply

folderflag = FileSystemObjectName.FolderExists(folderspec)

Parameters:

folderflag

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

FileSystemObjectName

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

folderspec

The parameter "folderspec" is used to specify the folder to be checked. The value of parameter "folderspec" should be a complete path specification if the specified folder does not exist in the current folder. The path of the folderspec can be either a absolute or relative path.

Return Values:

Boolean value

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

Remarks:

FileSystemObjectName should always refer to a FileSystemObject Object.

Examples:

  • Example of using the FolderExists method to check the existence of the specified folder

    ASP VBScript command:

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

    HTML web page ouput:

    True
    True
    True
    True
    True
    False

  • Example of using the FolderExists method to check the existence of the specified folder

    ASP JScript command:

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

    HTML web page ouput:

    true
    true
    true
    true
    true
    false

FileSystemObject.GetParentFolderName Method

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

Syntax:

FileSystemObjectName.GetParentFolderName(path)

 Or in VBScript. Imply

pfoldername = FileSystemObjectName.GetParentFolderName(path)

 Or in JScript. Imply

pfoldername = FileSystemObjectName.GetParentFolderName(path)

Parameters:

pfoldername

The parameter "pfoldername" is the name assigned to the parent folder name string returned by the method using the FileSystemObjectName.GetParentFolderName 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 parent folder name to be returned.

Return Values:

path of parent folder string

The method returns a string of the path of the parent folder name related to the specified FileSystemObject Object. The GetParentFolderName method returns the full path up to and including the name of the parent folder. The GetParentFolderName method returns a zero-length string ("") if there is no parent folder for the specified path. The GetPFolderName method only returns the full path of parent folder name string 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 GetParentFolderName method to return the path of parent folder name

    ASP VBScript command:

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

    HTML web page ouput:

    C:\working

    c:\
    \test
    test

  • Example of using the GetParentFolderName method to return the path of parent folder name

    ASP JScript command:

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

    HTML web page ouput:

    C:\working

    c:\
    \test
    test

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

Previous Month  APR  2012  Next Month
SMTWTFS
1234567
891011121314
15161718192021
22232425262728
2930

Sideway BICK Blog

20/03


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