Results 1 to 4 of 4

Thread: How do I access a local file?

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2004
    Posts
    11

    Question How do I access a local file?

    I need to access a file that is stored on a local machine.

    What is the code to say open "C:\RunThis.bat" when clicking cmdRun button? Forgive me if this is a simple question, but then it shouldnt take too long to answer.

  2. #2

    Thread Starter
    New Member
    Join Date
    Aug 2004
    Posts
    11
    Also I might add another thing...

    Is there a way to copy a local file to say make a backup?

    For instance click cmdBackup and "C:\Runthis.bat" creates "C:\RunthisBackup.bat"

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    use the SHELL command to execute a batch file, and SHELLEXECUTE to open the file. SHELL (filename,0) will hide the window, 1 will run it with normal focus.

    using FileSystemObject.CopyFile source,destination,overwrite
    will copy a file. overwrite can be True or False.

    Don't know if you are using a FSO, though.

    there is also FileCopy source, destination
    if you aren't

    Hope this helps.

    Last edited by dglienna; Aug 13th, 2004 at 11:19 PM.

  4. #4
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    You can use the Shell command which opens a program. To open a text file in notepad, for example:
    VB Code:
    1. Shell "notepad ""C:\testfile.txt"""
    ShellExecute is an API function (one which you must set a reference too) which will run a file in the default program.
    VB Code:
    1. 'Example
    2. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    3.  
    4. ShellExecute 0, "Open", "C:\RunThis.bat", "", "C:\", 1
    That will run the bat file in the default program, which is, Command Prompt. Other examples are HTML files in the defualt browser, IE, Netscape, or others..

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width