1. Win32 File Attribute Modification

Hi all,

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.

I searched the archive for libraries for dealing with file attributes, 
but only found info on looking at file attributes, not modifying them.  
Has someone come up with something I just missed?

Thanks,
Ted Fines

new topic     » topic index » view message » categorize

2. Re: Win32 File Attribute Modification

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 message » categorize

3. Re: Win32 File Attribute Modification

Juergen, you rock.  Thank you!

Derek, any chance Juergen's 'setFileInfo' code can be included in the next 
release of win32lib, to complement your 'getFileInfo' function?

Sincerely,
Ted Fines

--On Thursday, August 14, 2003 9:32 PM +0200 Juergen Luethje <j.lue at gmx.de> 
wrote:

>
>
> 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]
>
> --^----------------------------------------------------------------
> This email was sent to: fines at macalester.edu
>
>
> TOPICA - Start your own email discussion group. FREE!
>
>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu