Poster | Thread |
Deniil715
| |
Get and set file date in an arexx script?? Posted on 12-Aug-2014 19:27:06
| | [ #1 ] |
|
|
|
Elite Member |
Joined: 14-May-2003 Posts: 4236
From: Sweden | | |
|
| Is there a way to get a file's date stamp and then set it to another file?
I need to do this to be able to preserve the file date after processing a file.
It seems I can get the date stamp in raw format (days/minutes/ticks) using Statef() and then set it using a human readable format with C:setdate, but how to convert? There must be a better way, like some getdate function in C:, or a setdate function in arexx, but I cannot find any match. _________________ - Don't get fooled by my avatar, I'm not like that (anymore, mostly... maybe only sometimes) > Amiga Classic and OS4 developer for OnyxSoft. |
|
Status: Offline |
|
|
MichaelMerkel
| |
Re: Get and set file date in an arexx script?? Posted on 12-Aug-2014 19:32:09
| | [ #2 ] |
|
|
|
Cult Member |
Joined: 9-Mar-2003 Posts: 819
From: Ilvesheim, Germany | | |
|
| @Deniil715
i think the easiest way is to get it with the c:list command: list >t:dateoutput {file} lformat="%d" and read the output file with arexx...
at leas i did similar stuff..
regards... michael _________________ Michael Merkel (Michael.Merkel@gmx.net Home) Member of Amiga-Freunde Pfalz, OS4 Welt |
|
Status: Offline |
|
|
Severin
| |
Re: Get and set file date in an arexx script?? Posted on 12-Aug-2014 21:23:55
| | [ #3 ] |
|
|
|
Elite Member |
Joined: 19-Aug-2003 Posts: 2740
From: Gloucestershire UK | | |
|
| @Deniil715
Try:
info = statef("testfile") filedate = trasnslate(date('N',word(info,5),"I"),"-"," ") say filedate
Edit: deleted gibberish and tried again...
Last edited by Severin on 12-Aug-2014 at 10:43 PM. Last edited by Severin on 12-Aug-2014 at 10:32 PM. Last edited by Severin on 12-Aug-2014 at 10:06 PM. Last edited by Severin on 12-Aug-2014 at 10:01 PM.
_________________ OS4 Rocks X1000 beta tester, Sam440 Flex (733)
Visit the Official OS4 Support Site for more help.
It may be that your sole purpose is to serve as a warning to others. |
|
Status: Offline |
|
|
nbache
| |
Re: Get and set file date in an arexx script?? Posted on 12-Aug-2014 22:49:08
| | [ #4 ] |
|
|
|
Super Member |
Joined: 8-Apr-2003 Posts: 1034
From: Copenhagen, Denmark | | |
|
| @Deniil715
I have used the RexxMustHave library for this in several of my scripts. It has both RMH_GetFileDate and RMH_SetFileDate, among may other useful functions.
Best regards,
Niels
|
|
Status: Offline |
|
|
Severin
| |
Re: Get and set file date in an arexx script?? Posted on 12-Aug-2014 23:15:16
| | [ #5 ] |
|
|
|
Elite Member |
Joined: 19-Aug-2003 Posts: 2740
From: Gloucestershire UK | | |
|
| @nbache
Isn't RMH a thrid party library though? I like to avoid using those if possible. Been testing and came up with this...
/* test */ fname = "s:user-startup" info = statef(fname) fdate = TRANSLATE(DATE('N',word(info,5),"I"),"-"," ") hours = word(info, 6) % 60 mins = word(info, 6) // 60 secs = word(info, 7) % 50 ftime = right(hours,2,'0')':'right(mins,2,'0')':'right(secs,2,'0') say fname fdate ftime _________________ OS4 Rocks X1000 beta tester, Sam440 Flex (733)
Visit the Official OS4 Support Site for more help.
It may be that your sole purpose is to serve as a warning to others. |
|
Status: Offline |
|
|
Deniil715
| |
Re: Get and set file date in an arexx script?? Posted on 13-Aug-2014 12:27:23
| | [ #6 ] |
|
|
|
Elite Member |
Joined: 14-May-2003 Posts: 4236
From: Sweden | | |
|
| Thanks all!
I'll try whatever makes it easiest.
Where can I find the RMH library? This is for a private script so I don't mind using 3rd party libs. _________________ - Don't get fooled by my avatar, I'm not like that (anymore, mostly... maybe only sometimes) > Amiga Classic and OS4 developer for OnyxSoft. |
|
Status: Offline |
|
|
jPV
| |
Re: Get and set file date in an arexx script?? Posted on 13-Aug-2014 13:01:37
| | [ #7 ] |
|
|
|
Cult Member |
Joined: 11-Apr-2005 Posts: 820
From: .fi | | |
|
| @Deniil715
Quote:
Deniil715 wrote:
Where can I find the RMH library? |
Aminet of course._________________ - The wiki based MorphOS Library - Your starting point for MorphOS - Software made by jPV^RNO |
|
Status: Offline |
|
|
broadblues
| |
Re: Get and set file date in an arexx script?? Posted on 13-Aug-2014 13:11:58
| | [ #8 ] |
|
|
|
Amiga Developer Team |
Joined: 20-Jul-2004 Posts: 4446
From: Portsmouth England | | |
|
| @Severin
Where does this statef() function come from? It's not a standard arexx function.
7.AmigaOS4:> rx "say statef('ram:t/usb.log')" +++ Error 15 in line 1: Function not found Command returned 10/15: Function not found
Some other script of yours must be loading a library in rexx?
_________________ BroadBlues On Blues BroadBlues On Amiga Walker Broad |
|
Status: Offline |
|
|
broadblues
| |
Re: Get and set file date in an arexx script?? Posted on 13-Aug-2014 13:19:49
| | [ #9 ] |
|
|
|
Amiga Developer Team |
Joined: 20-Jul-2004 Posts: 4446
From: Portsmouth England | | |
|
| |
Status: Offline |
|
|
Severin
| |
Re: Get and set file date in an arexx script?? Posted on 13-Aug-2014 16:48:22
| | [ #10 ] |
|
|
|
Elite Member |
Joined: 19-Aug-2003 Posts: 2740
From: Gloucestershire UK | | |
|
| @broadblues
Seems to work fine without that and as rexxsupport.library is a system component I don't see a need to check for it...
If it's not there they have far worse problems than whether my pointless example test script works or not.
edit:
hmmm... ok, it's borked and does need that, script doesn't work today, no idea what loaded it though but then it's not my problem, Deniil715 already has statef() working, it's the date and time conversion he wanted.
Last edited by Severin on 13-Aug-2014 at 04:56 PM.
_________________ OS4 Rocks X1000 beta tester, Sam440 Flex (733)
Visit the Official OS4 Support Site for more help.
It may be that your sole purpose is to serve as a warning to others. |
|
Status: Offline |
|
|
broadblues
| |
Re: Get and set file date in an arexx script?? Posted on 13-Aug-2014 17:03:18
| | [ #11 ] |
|
|
|
Amiga Developer Team |
Joined: 20-Jul-2004 Posts: 4446
From: Portsmouth England | | |
|
| @Severin
It is a system component but it's not automatiacally loaded into the ARexx environment.
An odd quirk of the ARexx system is that a function library loaded by a scripts is available to all subsequant scripts until a script removes it. So the fact that your tests work from the comand line or from acsript that doesn't load the rexxupport.library shows you run a script that does so early in your session.
All scripts requireing it should test for it (with SHOW('L',"rexxsupport.library") and load it if not present
eg:
IF ~ SHOW('L', "rexxsupport.library" ) THEN DO
IF ADDLIB('rexxsupport.library', 0, -30,0) THEN NOP ELSE DO SAY 'ARexx support library not available, exiting' EXIT 10 /*Exit if ADDLIB() failed*/ END END
Since the library is only added if not present, there no open count like there would be with opening alibrary in C so removing it at the end of the script with REMLIB() could cuase issues if mutiple scripts are running, so it's generally not done.
_________________ BroadBlues On Blues BroadBlues On Amiga Walker Broad |
|
Status: Offline |
|
|
Severin
| |
Re: Get and set file date in an arexx script?? Posted on 13-Aug-2014 18:11:50
| | [ #12 ] |
|
|
|
Elite Member |
Joined: 19-Aug-2003 Posts: 2740
From: Gloucestershire UK | | |
|
| @broadblues
I'd already added it before reading your post and made it useful by being able to throw any filename at it.
/* fileinfo */ parse arg fname if fname="" then do say 'No filename' exit end
if ~show('L','rexxsupport.library') then do if ~addlib('rexxsupport.library',0,-30,0) then do say 'rexxsupport.library not found.' exit end end
info = statef(fname) if info > "" then do if word(info, 1) = 'FILE' then do fdate = TRANSLATE(DATE('N',word(info,5),"I"),"-"," ") hours = word(info, 6) % 60 mins = word(info, 6) // 60 secs = word(info, 7) % 50 ftime = right(hours,2,'0')':'right(mins,2,'0')':'right(secs,2,'0') say fname word(info,2) word(info,4) fdate ftime exit end else do say '"'fname'" is a drawer.' exit end end say '"'fname'" not found'
Edited for typos...Last edited by Severin on 13-Aug-2014 at 06:44 PM. Last edited by Severin on 13-Aug-2014 at 06:44 PM.
_________________ OS4 Rocks X1000 beta tester, Sam440 Flex (733)
Visit the Official OS4 Support Site for more help.
It may be that your sole purpose is to serve as a warning to others. |
|
Status: Offline |
|
|
Severin
| |
Re: Get and set file date in an arexx script?? Posted on 13-Aug-2014 19:23:32
| | [ #13 ] |
|
|
|
Elite Member |
Joined: 19-Aug-2003 Posts: 2740
From: Gloucestershire UK | | |
|
| @Deniil715
After a little fiddling... source date, time and protection bits are copied to dest.
/* CDTAB - Copy Date Time And Bits*/ parse arg source dest
source = strip(source) dest = strip(dest)
if source="" or dest = "" then do say 'Required argument missing.' exit 10 end
if ~show('L','rexxsupport.library') then do if ~addlib('rexxsupport.library',0,-30,0) then do say 'rexxsupport.library not found.' exit 10 end end
info = statef(source) if info > "" then do if word(info, 1) = 'FILE' then do fdate = TRANSLATE(DATE('N',word(info,5),"I"),"-"," ") hours = word(info, 6) % 60 mins = word(info, 6) // 60 secs = word(info, 7) % 50 ftime = right(hours,2,'0')':'right(mins,2,'0')':'right(secs,2,'0') address command setdate '"'dest'"' fdate ftime protect '"'dest'" clear' bits = strip(translate(word(info,4),' ','-')) protect '"'dest'" add 'bits exit end else do say '"'fname'" is a drawer.' exit 10 end end say '"'fname'" not found' exit 10
Last edited by Severin on 13-Aug-2014 at 07:37 PM.
_________________ OS4 Rocks X1000 beta tester, Sam440 Flex (733)
Visit the Official OS4 Support Site for more help.
It may be that your sole purpose is to serve as a warning to others. |
|
Status: Offline |
|
|
nbache
| |
Re: Get and set file date in an arexx script?? Posted on 13-Aug-2014 22:46:23
| | [ #14 ] |
|
|
|
Super Member |
Joined: 8-Apr-2003 Posts: 1034
From: Copenhagen, Denmark | | |
|
| BTW, one reason for rexxsupport.library to be open already is if the user has an rxlib statement loading it in e.g. User-Startup.
Some users prefer to do that if they run lots of ARexx scripts, but in general I also prefer to have the check in the script so as to avoid relying on the user (/myself) remembering to use rxlib.
Best regards,
Niels
|
|
Status: Offline |
|
|
Deniil715
| |
Re: Get and set file date in an arexx script?? Posted on 17-Aug-2014 20:38:30
| | [ #15 ] |
|
|
|
Elite Member |
Joined: 14-May-2003 Posts: 4236
From: Sweden | | |
|
| @Severin
I used your example and it work perfectly, except.... How does one escape special characters in AmigaDOS?
It seems this does nothing: SetDate ram:[foo]/bar Because of the [] that I have in some paths. I've run into similar problems before with AmigaDOS commands and perentheses. Very annoying. In bash one just \backslash anything that should not be parsed, or put the whole thing in 'single' quotes. - Not working in AmigaDOS
Any idea? _________________ - Don't get fooled by my avatar, I'm not like that (anymore, mostly... maybe only sometimes) > Amiga Classic and OS4 developer for OnyxSoft. |
|
Status: Offline |
|
|
broadblues
| |
Re: Get and set file date in an arexx script?? Posted on 17-Aug-2014 22:10:43
| | [ #16 ] |
|
|
|
Amiga Developer Team |
Joined: 20-Jul-2004 Posts: 4446
From: Portsmouth England | | |
|
| @Deniil715
Quote:
Because of the [] that I have in some paths. I've run into similar problems before with AmigaDOS commands and perentheses. Very annoying. In bash one just \backslash anything that should not be parsed, or put the whole thing in 'single' quotes. - Not working in AmigaDOS
|
The AmigaDos escape character is *. It only works in double quoted strings.
As far as AmigaDOS is concerned a single quote is not a quote but a character, except that in the context of pattern matching it can be used to escape the special characters. In this context you need a single single quote precedeing the character.
So your ram:[foo]/bar must be
ram:'[foo']/bar
the [] defines a group of charaters to be mtched in a file name.
I would avoid using anything but alphanumerics and "_-." in file names, you just make your life difficult otherwise.
Last edited by broadblues on 17-Aug-2014 at 10:31 PM.
_________________ BroadBlues On Blues BroadBlues On Amiga Walker Broad |
|
Status: Offline |
|
|
Deniil715
| |
Re: Get and set file date in an arexx script?? Posted on 18-Aug-2014 8:53:35
| | [ #17 ] |
|
|
|
Elite Member |
Joined: 14-May-2003 Posts: 4236
From: Sweden | | |
|
| @broadblues
Quote:
I would avoid using anything but alphanumerics and "_-." in file names, you just make your life difficult otherwise. |
Sure, but it's not easy to hunt and rename everything that comes in... I have a scheme that renames all () in mp3 files into {} though, to make scripts from DOpus work properly._________________ - Don't get fooled by my avatar, I'm not like that (anymore, mostly... maybe only sometimes) > Amiga Classic and OS4 developer for OnyxSoft. |
|
Status: Offline |
|
|
Severin
| |
Re: Get and set file date in an arexx script?? Posted on 18-Aug-2014 16:30:25
| | [ #18 ] |
|
|
|
Elite Member |
Joined: 19-Aug-2003 Posts: 2740
From: Gloucestershire UK | | |
|
| @Deniil715
Quote:
Sure, but it's not easy to hunt and rename everything that comes in... I have a scheme that renames all () in mp3 files into {} though, to make scripts from DOpus work properly. |
Do you still have the filecleaner sources? I emailed you requesting an option or standalone version to work on directory names for this very problem years ago. maybe it's time to look into it?
I use list recursivly with lfomat to build scripts but it's impossible with []{}*'`~ etc in a dir name, it halts with a not found error. Even if it just printed what it couldn't find that would enable you to find and edit it easily.
I've asked for an switch to turn off pattern matching for list etc. but that's far too low a priority to be considered.
I suppose I'll have to roll my own in python or amiblitz. never did get my head round recursive stuff though...Last edited by Severin on 18-Aug-2014 at 04:32 PM.
_________________ OS4 Rocks X1000 beta tester, Sam440 Flex (733)
Visit the Official OS4 Support Site for more help.
It may be that your sole purpose is to serve as a warning to others. |
|
Status: Offline |
|
|
Severin
| |
Re: Get and set file date in an arexx script?? Posted on 18-Aug-2014 17:11:15
| | [ #19 ] |
|
|
|
Elite Member |
Joined: 19-Aug-2003 Posts: 2740
From: Gloucestershire UK | | |
|
| @Deniil715
Quote:
Deniil715 wrote: @Severin
I used your example and it work perfectly, except.... How does one escape special characters in AmigaDOS?
It seems this does nothing: SetDate ram:[foo]/bar Because of the [] that I have in some paths. I've run into similar problems before with AmigaDOS commands and perentheses. Very annoying. In bash one just \backslash anything that should not be parsed, or put the whole thing in 'single' quotes. - Not working in AmigaDOS
Any idea? |
This is totally untested but should/might work... replace « with less than and » with greater than as I can't disaply them here.
Edit: or if you have dicpng (os4depot) version 1: version 2:
/* CDTAB - Copy Date Time And Bits*/ parse arg source dest
source = strip(source) dest = strip(dest)
if source="" or dest = "" then do say 'Required argument missing.' exit 10 end
if ~show('L','rexxsupport.library') then do if ~addlib('rexxsupport.library',0,-30,0) then do say 'rexxsupport.library not found.' exit 10 end end
source = escape(source) dest = escape(dest) /* or maybe: call escape source source = Return call escape dest dest = Return */
info = statef(source) if info > "" then do if word(info, 1) = 'FILE' then do fdate = TRANSLATE(DATE('N',word(info,5),"I"),"-"," ") hours = word(info, 6) % 60 mins = word(info, 6) // 60 secs = word(info, 7) % 50 ftime = right(hours,2,'0')':'right(mins,2,'0')':'right(secs,2,'0') address command setdate '"'dest'"' fdate ftime protect '"'dest'" clear' bits = strip(translate(word(info,4),' ','-')) protect '"'dest'" add 'bits exit end else do say '"'fname'" is a drawer.' exit 10 end end say '"'fname'" not found' exit 10
escape: ARG path if verify(path,"()[]{}«»~`'", 'M') > 0 temp = "" Do x = 1 to length(path): char = substr(path,x,1) Select When char = "(" then temp = temp + "'(" When char = ")" then temp = temp + "')" When char = "[" then temp = temp + "'[" When char = "]" then temp = temp + "']" When char = "{" then temp = temp + "'{" When char = "}" then temp = temp + "'}" When char = "«" then temp = temp + "'«" When char = "»" then temp = temp + "'»" When char = "~" then temp = temp + "'~" When char = "`" then temp = temp + "'`" When char = "'" then temp = temp + "''" otherwise temp = temp + char end end end return temp
edit... escape routine 2 also untested:
escape2: ARG path if verify(path,"()[]{}~`'", 'M') > 0 temp = "" Do x = 1 to length(path): char = substr(path,x,1) if verify(char,"()[]{}~`'", 'M') > 0 then temp = temp"'"char else temp = temp || char end end return temp
Last edited by Severin on 18-Aug-2014 at 05:45 PM. Last edited by Severin on 18-Aug-2014 at 05:39 PM. Last edited by Severin on 18-Aug-2014 at 05:28 PM. Last edited by Severin on 18-Aug-2014 at 05:21 PM.
_________________ OS4 Rocks X1000 beta tester, Sam440 Flex (733)
Visit the Official OS4 Support Site for more help.
It may be that your sole purpose is to serve as a warning to others. |
|
Status: Offline |
|
|
Deniil715
| |
Re: Get and set file date in an arexx script?? Posted on 31-Aug-2014 10:58:30
| | [ #20 ] |
|
|
|
Elite Member |
Joined: 14-May-2003 Posts: 4236
From: Sweden | | |
|
| @Severin
Thanks. But I tried with ' in a shell manually and that didn't seem to work..? _________________ - Don't get fooled by my avatar, I'm not like that (anymore, mostly... maybe only sometimes) > Amiga Classic and OS4 developer for OnyxSoft. |
|
Status: Offline |
|
|