Re: Win32 File Attribute Modification

new topic     » goto parent     » topic index » view thread      » older message » newer message

Ted wrote:

> I need to modify some file attributes, but don't want to do a
> 'system("attrib ...")' call.  Something like result =
> setFileAttr(myfile,attribs) is what I'm looking for.

The following code was successfully tested with the Eu 2.4 interpreter
under Windows 98:

----------------------------[ begin code ]----------------------------
include dll.e
include machine.e

constant
   ATTR_NORMAL   = #00,   -- #00 is valid only if used alone.
   ATTR_READONLY = #01,   --   The other attributes can be added.
   ATTR_HIDDEN   = #02,
   ATTR_SYSTEM   = #04,
   ATTR_DIR      = #10,   -- #10 is ignored by set_attr().
   ATTR_ARCHIVE  = #20,   --   To create a directory, use the
                          --   CreateDirectory() function.

   KERNEL32 = open_dll("kernel32.dll"),
   ID_SETATTR = define_c_func(KERNEL32, "SetFileAttributesA",
                              {C_POINTER, C_ULONG}, C_LONG)


function set_attr (sequence name, atom attr)
   atom lpszName, ret

   lpszName = allocate_string(name)
   ret = c_func(ID_SETATTR, {lpszName, attr})
   free(lpszName)
   return ret     -- 0 on error
end function


? set_attr("c:\\autoexec.bat", ATTR_HIDDEN)
-----------------------------[ end code ]-----------------------------

Best regards,
   Juergen

-- 
 /"\  ASCII ribbon campain  | "Everything should be made as simple
 \ /  against HTML in       |  as possible, but not simpler."
  X   e-mail and news,      |
 / \  and unneeded MIME     | [Albert Einstein]

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu