Results 1 to 6 of 6

Thread: Objects in VBScript

  1. #1
    Join Date
    Jul 2010
    Posts
    25

    Objects in VBScript

    I have recently started learning the VBScript. So its obvious that I am not having knowledge of it. Actually we have been taught about the using an object in VBScript. But the fact, I was not able to get anything. I know that I cannot move forward without clearing the basic concepts. So I am requesting you to provide some notes regarding the topic. I am sure that some members out there (who are having enough knowledge about VBScript) will help me sooner. Any other information regarding the topic would be appreciable.

  2. #2
    Join Date
    Dec 2008
    Posts
    202

    Re: Objects in VBScript

    To use an object you must create an instance that is declared and a name. To do this you use the CreateObject command. The syntax for creating an object is:
    Code:
    September ObjectName = CreateObject ("object type")
    The FileSystemObject allows you to work with files and folders on your hard disk. This object is used to create other objects that will be the folder, file or drive. In the following example we take a look :
    Code:
    <script language="vbscript"> 
    
    Function showfile (folderspec) 
    Dim fso, folder, file, FileItem 
    
    Set fso = CreateObject ("Scripting.FileSystemObject") 
    Set folder = fso.GetFolder (folderspec) 
    September folder.Files file = 
    
    For Each file in FileItem 
    document.write FileItem & <br/> " 
    Next 
    End Function 
    
    Showfile ("c") 
    </ Script>
    The start of this function in an HTML page tells us that you are creating a situational hazard. In fact, the following function displays the files but as we shall see, there are also commands to delete files and folders.

  3. #3
    Join Date
    Dec 2008
    Posts
    161

    Re: Objects in VBScript

    Returning to the function showfile, you first created the object fso, that is the object that allows to work with the file system. With the next command "Set folder = fso.GetFolder (folderspec)" that is created the folder object and then "Set file = folder.Files" then create the object file. The rest of the program uses methods and properties of these objects, to be hours decrypts. The FileSystemObject has only one property, Drive, which returns a list of all available drives on your system.

  4. #4
    Join Date
    Apr 2008
    Posts
    193

    Re: Objects in VBScript

    The FileSystemObject has only one property, Drive, which returns a list of all available drives on your system.
    However, there are numerous methods for working with files and folders:
    • DriveExists (drive letter) returns True if the drive letter of specified there.
    • GetDrive (drive letter) returns a Drive object corresponding to the letter specified
    • GetDriveName (drive letter) returns the name drive letter corresponding to the specified
    • BuildPath (path, name) adds specified files or folders by name to the current path
    • CopyFolder (source, destination, overwrite) copy a folder from the source to the destination location, is overwritten if it already exists as a function of the overwrite parameter
    • CreateFolder (folder name) creates a folder
    • DeleteFolder (folder name, force) deletes a folder, with the force parameter = true gate the folders read-only
    • FolderExists (folder name) returns true or false if the specified folder exists or not
    • GetFolder (folder) returns a folder object corresponding to the specified folder.
    • GetParentFolderName (folder) return folder name other than that specified
    • MoveFolder (source, destination) moves to a folder
    • CopyFile (source, destination, overwrite) copy a file from the source to the destination location, is overwritten if it already exists as a function of the overwrite parameter
    • CreateTextFile (Route, overwrite, unicode) creates a text file in the specified location. The overwrite parameter, allows make it in writing over an existing file, unicode parameter allows you to save as ASCII or Unicode
    • DeleteFile (filename, force) deletes a file, with the force parameter = true delete also the files read-only
    • FileExists (file path) returns true or false if the specified file exists or not
    • GetExtensionName (path) returns the file extension
    • GetFile (path) returns a file object corresponding to the specified file
    • MoveFile (source, destination) moves a file
    • OpenTextFile (filename, iomode, create, format) create or open a text file using iomode to read, write or add as ASCII or Unicode.

  5. #5
    Join Date
    Mar 2008
    Posts
    232

    Re: Objects in VBScript

    The following code creates unFileSystemObject and lists the drives in the local machine:
    Code:
    Dim fso 
    Dim disk 
    
    'Create the FileSystemObject 
    Set fso = CreateObject ("Scripting.FileSystemObject") 
    
    document.write "discs on this machine are: 
    For Each disc fso.Drives 
    document.write "<BR> Drive =" & disk 
    next

  6. #6
    buckbunny Guest

    Re: Objects in VBScript

    VBScript is a scripting language developed by the activities of Microsoft Visual Basic for the blueprint. It is designed as a "lightweight" language used and fast translation of a variety of Microsoft environments. VBScript part, began in the Microsoft Windows Script Technology

Similar Threads

  1. How to run a .bat file with VBScript ?
    By troy in forum Software Development
    Replies: 8
    Last Post: 29-06-2012, 10:55 AM
  2. VBScript for .NET
    By Bharat89 in forum Software Development
    Replies: 3
    Last Post: 03-12-2009, 04:50 PM
  3. help with vbscript
    By andrakis2 in forum Networking & Security
    Replies: 3
    Last Post: 24-08-2009, 06:13 AM
  4. How to use Win32_NetworkAdapterConfiguration in VBScript
    By B_Hodge in forum Networking & Security
    Replies: 3
    Last Post: 06-06-2009, 09:35 PM
  5. How can I add a new line to vbscript?
    By Baani in forum Software Development
    Replies: 2
    Last Post: 29-05-2009, 04:54 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,657,551.76205 seconds with 17 queries