CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: File access

  1. #1
    Join Date
    Aug 1999
    Location
    Bangalore, INDIA
    Posts
    70

    File access

    Hi,
    can somebody give an equivalent API/ vb Function for the 'C' Access function , where in we can check access (read / write) to a file.
    Thanks,
    Sharath

    //code from msdn
    #include <io.h>
    #include <stdio.h>
    #include <stdlib.h>

    void main( void )
    {
    /* Check for existence */
    if( (_access( "ACCESS.C", 0 )) != -1 )
    {
    printf( "File ACCESS.C exists\n" );
    /* Check for write permission */
    if( (_access( "ACCESS.C", 2 )) != -1 )
    printf( "File ACCESS.C has write permission\n" );
    }
    }







  2. #2
    Join Date
    Apr 2000
    Posts
    737

    Re: File access

    check out FileAttr function, or this is the simplest solution when you want to access to C functions, create a DLL that wrap the function.

    HTH

    cksiow
    http://vblib.virtualave.net - share our codes




  3. #3
    Join Date
    May 2001
    Location
    New Jersey, USA
    Posts
    47

    Re: File access

    This will do just about what your C code does...


    private Sub Command1_Click()

    Dim MyFile as string
    Dim isReadOnly as Integer
    Dim msg as string

    MyFile = Dir$("c:\access.c", vbNormal) ' file existance

    If MyFile <> "" then
    msg = "The file ACCESS.C exists."

    isReadOnly = GetAttr("c:\access.c") And vbReadOnly ' file properties
    If isReadOnly > 0 then '
    msg = msg & vbCrLf & "The file ACCESS.C is read only."
    else
    msg = msg & vbCrLf & "The file ACCESS.C has full access."
    End If

    MsgBox msg

    else
    MsgBox "The file ACCESS.C does not exist."

    End If


    End Sub






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

Featured