Results 1 to 3 of 3

Thread: [RESOLVED] Read Write API - Setting file attributes

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    54

    Resolved [RESOLVED] Read Write API - Setting file attributes

    Has anyone else had problems with this API?

    I can't get the example to work. It always returns zero for nSizw.

    nSize = GetFileSize(hOrgFile, 0)

    Then I get Subscript out of range at
    ReDim bBytes(1 To nSize - Int(nSize / 2)) As Byte.

    Is this a know problem which people can help me with, or does anyone know a better way to ensure a file they are trying to write to is not "Read Only", and make "Read & Write".

    Thanks

  2. #2
    Junior Member
    Join Date
    Nov 2006
    Posts
    26

    Re: Read Write API - Setting file attributes

    Hello SlapHead109, I am just a new member but I know little about API may be this can help you in returning size of files, just don't read the bottom of my code as it belongs to another language which has the same function:

    VB Code:
    1. Private Const OF_READ = &H0&
    2. 'Equivalent to Kark98_K Function of OKL
    3. Private Declare Function lOpen Lib "kernel32" Alias "_lopen" (ByVal lpPathName As String, ByVal iReadWrite As Long) As Long
    4. 'Equivalent to MP_40 Or MP_44 Or WEHR_43 Structure of OKL
    5. Private Declare Function lclose Lib "kernel32" Alias "_lclose" (ByVal XFile As Long) As Long
    6. 'OKL has a fixed function: PPSH_BAR.SYS{SIZE OBS;}
    7. Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
    8. Dim lpFSHigh As Long
    9.  
    10. Public Sub GetInfoF(FilePath As String)
    11.     Dim Pointer As Long, sizeofthefile As Long
    12.     Pointer = lOpen(FilePath, OF_READ)
    13.     'size of the file
    14.     sizeofthefile = GetFileSize(Pointer, lpFileSizeHigh)
    15.     Label1.Caption = sizeofthefile & " bytes"
    16.     lclose Pointer
    17. End Sub
    18.  
    19. Private Sub command1_Click()
    20.     CommonDialog1.ShowOpen
    21.     GetInfoF CommonDialog1.FileName
    22. End Sub
    23. Private Sub Form_Load()
    24.     With CommonDialog1
    25.         .DialogTitle = "Select a file"
    26.         .Filter = "All the files|*.*"
    27.     End With
    28.     Command1.Caption = "Select a file"
    29. End Sub

  3. #3
    Member
    Join Date
    Oct 2006
    Location
    Noida,India
    Posts
    49

    Re: Read Write API - Setting file attributes

    Use FileSystemObject to change the file attribute (Add ref to Microsoft Scripting Runtime)
    Rajneesh

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