r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

Ladislav
6-Oct-2010
[18619x3]
right
(I just do not know on which machine the file is)
a related problem: how to remove the last character from a file in 
R3?
Graham
6-Oct-2010
[18622x2]
In my file replication tool I hit a snag ... when replicating directories 
I was not able to set the file date :(
ie. get-modes can't set directory dates
Ladislav
6-Oct-2010
[18624]
I suppose you mean Set-modes?
Graham
6-Oct-2010
[18625x2]
yes
Now that I think about it .. my NAS box has that problem .. I copy 
files to it, and the file dates are in the future because the box's 
time runs fast :(
Geomol
6-Oct-2010
[18627]
how to remove the last character from a file in R3?


I don't know, if it will be done differently in R3, but using R2 
I would do something like:

sz: length? p: open/binary %file
write/binary %newfile copy/part p sz - 1
close p
Ladislav
6-Oct-2010
[18628x2]
hmm, ugly
in R2 it can be simpler, but probably not in R3
Geomol
6-Oct-2010
[18630x2]
yeah! :-)
Is this better with your definition of 'ugly'?


write/binary %file copy/part read/binary %file (get in info? %file 
'size) - 1
Ladislav
6-Oct-2010
[18632]
- that is the same for me, I would like to just remove one character, 
not to copy the whole file
Geomol
6-Oct-2010
[18633]
Is that possible?
Ladislav
6-Oct-2010
[18634]
in R2 it is, as it looks
Geomol
6-Oct-2010
[18635x2]
I mean, is it possible in R2?
Could you show me?
Ladislav
6-Oct-2010
[18637]
port: open %file
remove back tail file
close port
Geomol
6-Oct-2010
[18638]
Neat! :)
Ladislav
6-Oct-2010
[18639]
remove back tail port is what I meant
Geomol
6-Oct-2010
[18640x2]
yes
And it doesn't work in R3 for some reason?
Ladislav
6-Oct-2010
[18642x2]
...at least not for me...
:-(
Geomol
6-Oct-2010
[18644x3]
Here (under windows) a unix format text file is changed to dos format, 
if I do, what you just suggested. So it become longer.
Doing open/binary and it works.
Using R3, I get:
** Script error: cannot use remove on port! value
Probably the same, you see.
ChristianE
6-Oct-2010
[18647]
Using R3, 

	>> clear back tail port

works for me.
Ladislav
6-Oct-2010
[18648x2]
aha, fine
thanks
Geomol
6-Oct-2010
[18650]
amazing!
ChristianE
6-Oct-2010
[18651]
That was just by luck.
Ladislav
6-Oct-2010
[18652x2]
Hmm, I thought, that OPEN does not create the file when it does not 
exist?
(in R2)
Pekr
6-Oct-2010
[18654]
in R2, you use open/new for such purpose (to create a file if it 
does not exist)
Ladislav
6-Oct-2010
[18655]
But, I need the exact opposite, to open touch a file only if it exists, 
which looks like not supported...
ChristianE
6-Oct-2010
[18656x2]
>> port: open/read %test

** Access Error: Cannot open /c/program files (x86)/rebol/view/test
** Near: port: open/read %test

isn't suited for your purpose, I guess.
Since if it exists, you'll have do do a second OPEN, the file may 
vanish in the meantime.
Ladislav
6-Oct-2010
[18658]
that is a problem, I need to touch the file, i.e. change the date, 
but, nevermind, I can make a work-around
ChristianE
6-Oct-2010
[18659]
*do do = to do
Izkata
6-Oct-2010
[18660]
On recreating touch:  Doesn't writing nothing work?  Seems to here...

write/append %Filename {}
Ladislav
6-Oct-2010
[18661x2]
checking...
hmm, does not do help here...
Izkata
6-Oct-2010
[18663]
Odd... oh well
Gregg
6-Oct-2010
[18664]
I use get/set-modes for my TOUCH, but it was only for local use.
Ladislav
6-Oct-2010
[18665x3]
this looks like working, in R2 as well as in R3, can you confirm?

touch: func [
    {touch the given FILE}
    file [file!]
] [
    file: open file
    clear tail file
    close file
]
The only problem I am having with it is, that it creates the given 
FILE, if it does not exist, while I would prefer the function to 
do nothing in that case
aha, looks like this does not work in 2.7.7 :-(
Sunanda
6-Oct-2010
[18668]
Nothing if file does not exist: add 
   if exists? file [...]