Results 1 to 3 of 3

Thread: Managing Files with VBScript

  1. #1
    Join Date
    Sep 2010
    Posts
    73

    Managing Files with VBScript

    To work with these examples you need to create a test folder in C: drive. Let's start with the copy the autoexec.bat file from C: to C:Trail. To do this you need the simple script:
    Code:
    <SCRIPT Language=vbscript> 
    <! - 
    Dim Drive, OggFile, origin, destination 
    source = "c: autoexec.bat" 
    target = "c: trail" 
    Set fso = CreateObject ("Scripting.FileSystemObject") 
    December OggFile fso.GetFile = (source) 
    OggFile.Copy destination, true 
    document.write "File" & & source "was 
    copied to "& target &". " 
    //--> 
    </SCRIPT>
    We associate this script with a function called by the click of a button:

    HTML Code:
    <HTML> 
    <HEAD> 
    <TITLE> Exercise </ TITLE> 
    </ HEAD> 
    <BODY> 
    
    <SCRIPT Language=vbscript> 
    <! - 
    function copy () 
    Dim Drive, OggFile, origin, destination 
    source = "c: autoexec.bat" 
    target = "c: trail" 
    Set fso = CreateObject ("Scripting.FileSystemObject") 
    December OggFile fso.GetFile = (source) 
    OggFile.Copy destination, true 
    msgbox "The file" & source & "has been copied to" & target & "." 
    end function 
    //--> 
    </SCRIPT> 
    <input type=button value=Copy> 
    </BODY> 
    </HTML>

  2. #2
    Join Date
    Sep 2010
    Posts
    73

    Re: Managing Files with JavaScript

    If pressing the copy button each time overwriting the file in the folder test. Our goal is now to see if the file already exists: only if this fails, it will be copied to the test. To do this, use the FileExists method. This method returns true if the file exists, false if it does not exist.

    HTML Code:
    <HTML> 
    <HEAD> 
    <TITLE> Exercise </TITLE> 
    </HEAD> 
    <BODY> 
    
    <SCRIPT Language=vbscript> 
    <! - 
    function copy () 
    Dim Drive, OggFile, origin, destination 
    source = "c: autoexec.bat" 
    target = "c: trial" 
    Set fso = CreateObject ("Scripting.FileSystemObject") 
    December OggFile fso.GetFile = (source) 
    fso.FileExists if (target & "autoexec.bat") then 
    MsgBox "There is already a file in the folder autoexec.bat trial." 
    else 
    OggFile.Copy destination, true 
    MsgBox "The file" & source & "has been copied to" & target & 
    "." End if 
    end function 
    //--> 
    </SCRIPT> 
    <input type=button value=Copy> 
    </BODY> 
    </HTML>

  3. #3
    Join Date
    Sep 2010
    Posts
    73

    Re: Managing Files with JavaScript

    We complete the work with a function to delete the files from the test:

    Code:
    function erase () 
    Dim OggFile, origin 
    source = "c: trialautoexec.bat" 
    Set fso = CreateObject ("Scripting.FileSystemObject") 
    December OggFile fso.GetFile = (source) 
    OggFile.Delete 
    MsgBox "The file" & source & "has been canceled." 
    end function
    Also in this feature we associate a button. Here's the code complete application:

    HTML Code:
    <HTML> 
    <HEAD> 
    <TITLE> Exercise </TITLE> 
    </HEAD> 
    <BODY> 
    
    <SCRIPT Language=vbscript> 
    <! - 
    function copy () 
    Dim Drive, OggFile, origin, destination 
    source = "c: autoexec.bat" 
    target = "c: trial" 
    Set fso = CreateObject ("Scripting.FileSystemObject") 
    December OggFile fso.GetFile = (source) 
    fso.FileExists if (target & "autoexec.bat") then 
    MsgBox "There is already a file in the folder autoexec.bat trial." 
    else 
    OggFile.Copy destination, true 
    MsgBox "The file" & source & "has been copied to" & target & 
    "." End if 
    end function 
    
    function erase () 
    Dim OggFile, origin 
    source = "c: trialautoexec.bat" 
    Set fso = CreateObject ("Scripting.FileSystemObject") 
    December OggFile fso.GetFile = (source) 
    OggFile.Delete 
    MsgBox "The file" & source & "has been canceled." 
    end function 
    //--> 
    </SCRIPT> 
    <input type=button value=Copy> 
    <input type=button value=Cancel> 
    </BODY> 
    </HTML>
    The most common operations that operate on those files are just views: existence, copy, delete and move. Moving a file is not mentioned among the examples, but is equal to the copy, except that instead of the Copy method using the Move method.

Similar Threads

  1. How to rename files based on other files with VBScript, help
    By Thomas Hewitt in forum Software Development
    Replies: 2
    Last Post: 07-09-2012, 11:13 AM
  2. How to create ZIP Files from Command-Line via VBScript?
    By FB in forum Windows Server Help
    Replies: 10
    Last Post: 22-12-2011, 12:18 AM
  3. VBScript for parsing multiple text files
    By mytorchedsoul in forum Software Development
    Replies: 1
    Last Post: 23-04-2010, 09:29 PM
  4. Graphical interface for managing text files
    By Vodka in forum Software Development
    Replies: 5
    Last Post: 03-03-2010, 10:32 AM
  5. FTP client for managing files !!
    By Romit in forum Windows Software
    Replies: 1
    Last Post: 01-01-2009, 10:50 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,714,300,245.48258 seconds with 17 queries