Guidance
指路人
g.yi.org
software / rapidq / Examples / File & Directory / fileAttribs.inc

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
' Set, get, reset or check a file's attribute(s) :)
' Note: Code provided as-is.

     $IFNDEF WIN32
      SHOWMESSAGE "Umm, you can't use fileAttribs.inc on platforms other than Windows 9x.": END
     $ENDIF

     $IFNDEF __FILEATTRIBS_INC: $DEFINE __FILEATTRIBS_INC
      $IFNDEF __RQINC
   '-- Define all the File Attribute constants here if RapidQ.inc isn't included
       CONST faReadOnly  = 1
       CONST faHidden    = 2
       CONST faSysFile   = 4
       CONST faVolumeID  = 8
       CONST faDirectory = 16
       CONST faArchive   = 32
       CONST faAnyFile   = 63
       CONST faNormal  = 128
       CONST faTmpFile = 256
       CONST faCompressed = 2048
      $ENDIF

      DECLARE FUNCTION ChMod LIB "kernel32" ALIAS "SetFileAttributesA" _
       (lpFileName AS STRING, dwFileAttributes AS DWORD) AS LONG

      DECLARE FUNCTION GetMod LIB "kernel32" ALIAS "GetFileAttributesA" _
       (lpFileName AS STRING) AS LONG

      DECLARE FUNCTIONI CanAccess(...) AS LONG

      DECLARE FUNCTION RstMod(lpFileName AS STRING) AS LONG

' A better Access function, implemented in Rapid-Q
      DIM CanAccess.ENOFILE AS LONG
      FUNCTIONI CanAccess(...) AS LONG: CanAccess.ENOFILE=0
       DIM lpFileName AS STRING, dwFileAttributes AS DWORD
       lpFileName=PARAMSTR$(1): dwFileAttributes=PARAMVAL(1)
       IF dwFileAttributes=0 THEN dwFileAttributes=faNormal

       IF GetMod(lpFileName)=dwFileAttributes THEN
  ' Access mode matches dwFileAttributes
        Result=1 ' True; this is its attribute
       ELSE
  ' Not its attribute. Let's find out why...
        IF FILEEXISTS(lpFileName)=0 THEN ' Oh, okay. File doesn't exist
         CanAccess.ENOFILE=1: Result=0
        ELSE
         Result=0 ' Well, it just didn't match
        END IF
       END IF
      END FUNCTIONI

' Resets file attributes to faNormal, restoring normal access
' R(e)s(e)t[File]Mod(e)

      DIM RstMod.ENOFILE AS LONG
      FUNCTION RstMod(lpFileName AS STRING) AS LONG: RstMod.ENOFILE=0
       IF FILEEXISTS(lpFileName)=0 THEN
        Result=0: RstMod.ENOFILE=1
       ELSE
        IF ChMod(lpFileName, faNormal)=0 THEN
         Result=0 ' For some reason we're not able to change the access mode, but it _does_ exist. Maybe it's locked
        ELSE
         Result=1
        END IF
       END IF
      END FUNCTION
     $ENDIF
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Fri 2023-1-27  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2003-08-24 10:17:44