How to access files ' properties under Windows
[1/11] from: christophe:coussement:mil:be at: 19-Apr-2002 9:24
Hi:
I'm looking for the library where I can find
the functions which access the files properties
(created/modified/accessed date, attributes, ...)
under Windows NT.
More specifically to make a file read only or to check
its read only status from a REBOL routine!
Any help welcome :)
Thanks,
[2/11] from: petr:krenzelok:trz:cz at: 19-Apr-2002 14:31
Coussement Christophe wrote:
>Hi:
>I'm looking for the library where I can find
<<quoted lines omitted: 7>>
>>==christophe
>>
I don't know if anything else can be known about the file in Rebol by
default, maybe using some special set/get-modes, but I looked at how
dir? function works ...
try e.g. following:
ble: make port! %user.r
query ble
probe ble
.... as you can see, the file info is load in the port structure. Maybe
some /state item could be filled in future by platform dependant info,
if not available already? You will probably need to try some Win32 API
functions to achieve what you described ...
-pekr-
[3/11] from: holger:rebol at: 19-Apr-2002 7:41
On Fri, Apr 19, 2002 at 09:24:04AM +0200, Coussement Christophe wrote:
> Hi:
> I'm looking for the library where I can find
<<quoted lines omitted: 3>>
> More specifically to make a file read only or to check
> its read only status from a REBOL routine!
You don't need routines for that. REBOL can do that by itself,
and in a platform-independent way. Check http://www.rebol.com/docs/core25.html
and in particular the section on get/set-modes.
--
Holger Kruse
[kruse--nordicglobal--com]
[4/11] from: greggirwin:mindspring at: 19-Apr-2002 11:05
hi Christophe,
<< I'm looking for the library where I can find
the functions which access the files properties
(created/modified/accessed date, attributes, ...)
under Windows NT.
More specifically to make a file read only or to check
its read only status from a REBOL routine! >>
As Holger pointed out get-modes and set-modes are what you want to use.
Here's a little routine that might give you a start.
attr: func [
{Return current attributes for the file.}
f [file!]
/with {Retrieve only selected attributes.}
sel {Selected attributes to retrieve.}
/avail {Return a list of attributes available for the file.}
/copy {Copy all attributes, which are safe to copy, to f2.}
f2 [file!]
/local a
][
if with [return get-modes f sel]
if avail [return get-modes f 'file-modes]
if copy [
;set-modes f2 a: get-modes f get-modes f 'copy-modes
; Core 2.5 includes full-path, which it shouldn't
set-modes f2 a: get-modes f exclude get-modes f 'copy-modes
[full-path]
return a
]
get-modes f get-modes f 'file-modes
]
; >> attr/with f 'owner-write
; == true
; >> attr/with f [creation-date owner-write]
; == [creation-date: 31-Oct-2001/12:47:51-7:00 owner-write: true]
; >> attr/avail f
; == [creation-date access-date modification-date owner-write archived
hidden system f
; ull-path]
; >> attr/copy f f2
; == [creation-date: 31-Oct-2001/12:47:51-7:00 access-date:
21-Mar-2002/0:00-7:00 modi
; fication-date: 21-Mar-2002/12:11:24-7:00 owner-...
owner-write is the inverse equivalent of read-only.
HTH!
--Gregg
[5/11] from: anton:lexicon at: 20-Apr-2002 2:58
I have a demo program here:
http://anton.idatam.com.au/rebol/util/demo-show-file-modes.r
Rebol.com/Sites/Anton/Util/demo-show-file-modes.r
Actually, I would like to take this opportunity to
ask people out there on the list from different
platforms than mine to test this.
I have Win2k.
I would like someone with Amiga, linux, mac etc.
to try it out and report any problems.
The window is supposed to show whichever modes
are supported by the OS it's on, and allow you
to modify them.
But I know my code doesn't handle certain datatypes
(I am not even sure which datatypes are going to
show up.) At least string! can be found in
the file comment on Amiga, for instance, and I
don't handle it very well.
Note, to see the available file-modes the OS supports:
probe modes: get-modes %afile 'file-modes
and then to see the file-modes of a file:
probe get-modes %afile modes
Regards,
Anton.
[6/11] from: petr:krenzelok:trz:cz at: 19-Apr-2002 19:26
Holger Kruse wrote:
>On Fri, Apr 19, 2002 at 09:24:04AM +0200, Coussement Christophe wrote:
>>Hi:
<<quoted lines omitted: 9>>
>and in a platform-independent way. Check http://www.rebol.com/docs/core25.html
>and in particular the section on get/set-modes.
I thought so :-) Well, I just looked into docs and it works a little bit
strange way - I mean - syntax ...
----------
->> get-modes somefileordir 'file-modes
== [file-note creation-date archived script (...a few more...) ]
To obtain the actual mode settings for a port the returned block has to
be used in another call to get-modes:
->> get-modes somefileordir get-modes somefileordir 'file-modes
== [file-note: "cool graphics" creation-date: 1-Jan-2000 archived: true
script: false]
-------------
why does not 'get-modes directly return an object, as for e.g. errors
do? Wouldn't it simplify the way it works? You return the block of words
anyway, as seen in the first case, so it could be:
modes: get-modes %user.r 'file-modes
modes/creation-date
; or even checking ...
if word? in modes 'creation date [modes/creation-date]
... looks better than:
modes: context get-modes %user.r get-modes %user.r 'file-modes
Well, just my opinion :-) ... but Holger, I have to ask anyway - will it
be changed for Core 2.6? :-)
-pekr-
[7/11] from: ammon:rcslv at: 19-Apr-2002 12:10
Hi,
Running Linux Redhat 7.2, the available modes are:
[status-change-date modification-date access-date owner-name group-name
owner-id group-id owner-read owner-write owner-execute group-read group-write
group-execute world-read world-write world-execute set-user-id set-group-id
full-path]
Your script threw the following error when I pressed the "undo all changes"
button:
** Script Error: Invalid argument: status-change-date
** Where: func [face value][
set-modes file values
temp-lay: layout build-lay-block
lay/size: temp-lay/size
lay/pane: temp-lay/pane
show lay
]
** Near: set-modes file values
temp-lay: layout
HTH
Ammon
A short time ago, Anton, sent an email stating:
[8/11] from: holger::rebol::net at: 19-Apr-2002 10:57
On Fri, Apr 19, 2002 at 07:26:41PM +0200, Petr Krenzelok wrote:
> why does not 'get-modes directly return an object, as for e.g. errors
> do? Wouldn't it simplify the way it works? You return the block of words
<<quoted lines omitted: 5>>
> ... looks better than:
> modes: context get-modes %user.r get-modes %user.r 'file-modes
The problem with that is that on some platforms getting some of those
settings can take a non-trivial amount of time, e.g. certain types of
file properties with network-mounted filesystems. You don't want the
OS to spend a lot of time getting modes that you are not interested
in. The other problem with this is that for setting the modes you would
have to pass in the whole object, and then set-modes would somehow
have to figure out which modes have changed. Not very practical.
> Well, just my opinion :-) ... but Holger, I have to ask anyway - will it
> be changed for Core 2.6? :-)
No. A few modes may be added though, here and there.
--
Holger Kruse
[kruse--nordicglobal--com]
[9/11] from: christophe:coussement:mil:be at: 22-Apr-2002 9:28
Thanks a lot, fellows REBOLians :)
How could I think REBOL couldn't handle it directly ? Shame on me ;-P
==christophe
[10/11] from: chalz:earthlink at: 1-Aug-2002 0:58
I know that this is *insanely* late, but I just finally got around to this
message. (I've been deleting messages/threads I'm not interested in, and
saving interesting ones for later. Now happens to be later :P )
<snip>
> >You don't need routines for that. REBOL can do that by itself,
> >and in a platform-independent way. Check
http://www.rebol.com/docs/core25.html
> >and in particular the section on get/set-modes.
> >
<<quoted lines omitted: 4>>
> == [file-note creation-date archived script (...a few more...) ]
<snip>
Actually, I just read the text on it (the core25.html I have is more of a
changelog; heh). I rather like the format. I think that the builtin help
needs to be extended a touch, but otherwise, after having read the actual
documentation, I think this is a neat system. Of course, there lies the
problem that not all modes are available on all OS's, so you have to code with
that in mind. But the basics are available all around. So if you're already
familiar with what modes are available on all or target platforms, it's an easy
task:
get-modes %file 'read
Cool.
Um, though, I've encountered a problem...
>> get-modes %index.html 'file-modes
== [creation-date access-date modification-date owner-write archived hidden
system full-path]
>> get-modes %index.html 'port-modes
== [read write binary lines no-wait direct]
>> get-modes %index.html 'read
== false
>> get-modes %index.html 'write
== false
>> get-modes %index.html 'binary
== false
>> set-modes %index.html [read: true]
** Script Error: Invalid argument: read
** Near: set-modes %index.html [read: true]
>> set-modes %index.html [write: true]
** Script Error: Invalid argument: write
** Near: set-modes %index.html [write: true]
>> set-modes %index.html [binary: true]
>> get-modes %index.html 'binary
== false
>> get-modes %index.html 'hidden
== false
>> set-modes %index.html [hidden: true]
>> get-modes %index.html 'hidden
== true
>>
Am I missing something? Why are read/write unsettable? I know the
documentation says that only binary, lines and no-wait are settable... but why?
--Charles
[11/11] from: anton:lexicon at: 2-Aug-2002 3:53
I think you are asking this question because
you really want to control the "read only"
file attribute flag.
In rebol, this is the 'owner-write file-mode.
Anton.
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted