Results 1 to 4 of 4

Thread: FileSystem Object in VBScript

  1. #1
    Join Date
    Jul 2010
    Posts
    93

    FileSystem Object in VBScript

    Thanks FileSystem object through VBScript is possible to know about disks, folders and files of a user. Fortunately for you, before providing this information, it warned with a message like this:


    If you try to click on this link , you'll see a message like in the picture, do not worry, the page you will see only information on your hard drive. As with any object, VBScript to instantiate the object must be a syntax like the following:
    Code:
    Set fso = CreateObject ("Scripting.FileSystemObject")
    Now the fso object will have properties and methods that will allow it to set or read information about the File System. To get a result like the previous example, we used the following code:
    Code:
    <SCRIPT Language=vbscript> 
    <! - 
    Dim drive 
    drive = "C:" 
    Set fso = CreateObject ("Scripting.FileSystemObject") 
    document.write "Your C drive has" 
    & FormatNumber (fso.GetDrive (drive). TotalSize, 0) 
    & "Bytes" 
    //--> 
    </ SCRIPT>
    As can be seen from the object FileSystem fso, was called the object with the syntax fso.GetDrive drive (drive). From this object was displayed TotalSize property that represents the size of the drive.

  2. #2
    Join Date
    Dec 2008
    Posts
    183

    Re: FileSystem Object in VBScript

    FileSystem object you can retrieve other objects such as the Folder object, the object and the Object File TextStream. Let's see how:
    FileSystem object instance:
    Code:
    Set fso = CreateObject ("Scripting.FileSystemObject")
    Drive object instance:
    Code:
    September oggDrive fso.GetDrive = ("C")
    Folder object instance:
    Code:
    September oggCartella fso.GetFolder = ("c: winnt")
    Instance of the File
    Code:
    September oggFile fso.GetFile = ("c: autoexec.bat")
    Instance object TextStream
    Code:
    September OggTextStream oggFile.OpenAsTextStream = (1)
    Create objects, it now becomes easier knowing able to exploit the potential methods and properties.

  3. #3
    Join Date
    Dec 2008
    Posts
    202

    Leafing through the HardDisk

    The purpose of this application is to display the contents of the harddisk, as does Windows Explorer. The first step is to see the folders and files in the root:
    Code:
    <SCRIPT Language=vbscript> 
    <! - 
    Dim drive, folder, subfolder, elemFolder 
    path = "C:" 
    Set fso = CreateObject ("Scripting.FileSystemObject") 
    Set folder = fso.GetFolder (path) 
    September subfolder = folder.Subfolders 
    document.write path & "<br> 
    For Each subfolder in elemFolder 
    document.write "<b>" & replace (lcase (elemFolder), lcase (path & ),"") 
    "</ B> <br> next 
    September folder.files files = 
    For Each file in elemFile 
    document.write "" & replace (lcase (elemFile), lcase (path & ),"") 
    "<br>" Next 
    //--> 
    </ SCRIPT>
    In the variable path is entered the name of the folder to be scanned, in this case we chose the root of C drive Objects are created folder and subfolder: it contains all the folders in your folder. To view the various subfolders are made using a For Each loop. The path of each subdirectory, replace with the command, which is released as part of the parent folder. The same principle is adopted to read the files in the path. To distinguish files from folders, they are in bold.

  4. #4
    Join Date
    Mar 2008
    Posts
    232

    Re: FileSystem Object in VBScript

    I would like give the result of coding provided by the "pancham". Result of the script (reportedly, of course, to hard drive):
    Code:
    C: 
    documents and settings 
    inetpub 
    program files 
    recycler 
    winnt 
    autoexec.bat 
    boot.bak 
    boot.ini 
    config.sys 
    io.sys 
    msdos.sys 
    ntdetect.com 
    ntldr 
    pagefile.sys
    The script can be inserted into a function that receives as parameter the path. Now we have to make the folder names clickable. Clicking on the name of the folder, the path of the folder is passed to the function which redraws the tree with all subfolders and files. This script uses some commands like the span tags and innerHTML does not own the VBScript, but that increase the capabilities of this language.
    HTML Code:
    <HTML> 
    <HEAD> 
    Visual Studio 6.0"> <META NAME="GENERATOR" Content="Microsoft 
    <TITLE> </ TITLE> 
    </ HEAD> 
    <BODY> 
    
    <SCRIPT Language=vbscript> 
    <! - 
    navigation function (path) 
    Dim drive, folder, subfolder, elemFolder 
    Set fso = CreateObject ("Scripting.FileSystemObject") 
    Set folder = fso.GetFolder (path) 
    September subfolder = folder.Subfolders 
    carfiles.innerHTML = path & "<br> 
    For Each subfolder in elemFolder 
    nomefolder = replace (lcase (elemFolder), lcase (path ),"") 
    carfiles.innerHTML carfiles.innerHTML & = "<b> <span 
    style = "cursor: hand" "" & replace (elemFolder ,"","") & "')"">" nomefolder & & "</ span> </ b> <br> 
    next 
    September folder.files files = 
    For Each file in elemFile 
    carfiles.innerHTML carfiles.innerHTML = & "" & 
    replace (lcase (elemFile), lcase (path ),"") & "<br> next 
    end function 
    //--> 
    </ SCRIPT> 
    
    <div name=carfiles id=carfiles> <span style = "cursor: hand" 
    C :')"> C: </ span> </ div> 
    </ BODY> 
    </ HTML>
    The only thing missing to make the tree fully navigable, is the ability to navigate backwards. It might be interesting to try adding this new feature.

Similar Threads

  1. Replies: 9
    Last Post: 10-09-2011, 11:10 PM
  2. Replies: 6
    Last Post: 06-06-2011, 01:34 AM
  3. Replies: 3
    Last Post: 08-01-2011, 06:20 AM
  4. Differents between object and static object
    By Sarfaraj Khan in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 01:11 PM
  5. Object reference not set to an instance of an object
    By KAIRU26 in forum Software Development
    Replies: 3
    Last Post: 05-09-2009, 08:14 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,713,530,144.41920 seconds with 17 queries