Login
Username:

Password:

Remember me



Lost Password?

Register now!
Sections
Who's Online
52 user(s) are online (45 user(s) are browsing Forums)

Members: 0
Guests: 52

more...
Support us!
Recent OS4 Files
OS4Depot.net





Help with Arexx Script
Just popping in
Joined:
2008/10/18 10:25
From Auckland, New Zealand
Posts: 58
Hi everyone,

I was hoping someone could give me some tips with an arexx script I'm working on.

I often receive or download archives that have files inside them that aren't in a directory. I have to create an archive to file the contents, so I wanted to write an arexx script that takes the archive name, snips off the last 4 characters (the suffix) and creates a folder with that name.

/* Create Folder*/

parse arg file drawer
address command

chars 
length(file)

newdir left(file,chars-4)

cd drawer
makedir newdir


I'm calling it from Filer with rx CreateDrawer.rexx {ou} {d} , where {ou} is the selected archive and {d} is the current dir.

The script works fine, however it gets broken by empty spaces in the filename. It looks like when it reaches a space in the filename, it stops reading, so "Customer images Sept 2019.zip" gets parsed as simply "Customer". Because it snips off the last 4 characters, if there's less than 4 characters in front of a space, the result is an error.

Does anyone know a way around this?

   Report Go to top

Re: Help with Arexx Script
Just popping in
Joined:
2007/12/19 12:36
From Finland
Posts: 28

   Report Go to top

Re: Help with Arexx Script
Quite a regular
Joined:
2009/4/28 3:57
From Adelaide, Australia
Posts: 898
@daveyw

Here's my quick and dirty fix (Example only. It doesn't cut the last 4 characters):

/**/
Parse Arg Args

IF Left(Args,1)='"' THEN Parse Var Args '"'File'" 'Drawer
ELSE Parse Var Args File' 'Drawer

Drawer
=Strip(Drawer,,'"')

SAY File
SAY Drawer
Exit


6.RAM Disk:> rx test "1 2" 2
1 2
2
6.RAM Disk:> rx test "1 2" "2 3"
1 2
2 3
6.RAM Disk:> rx test 1 2 3
1
2 3
6.RAM Disk:> rx test 1 "2 3"
1
2 3

   Report Go to top

Re: Help with Arexx Script
Just can't stay away
Joined:
2008/1/6 17:56
From Pennsylvania, USA
Posts: 1280
@daveyw
It is irritating when you extract an archive and discover that it didn't extract into a directory but mixed all the archive files with existing files in the destination directory. Here is an AmigaDOS script that should create a directory from file & directory arguments:
Create new drawer in existing drawer from filename

.key file/A,drawer/A
.bra {
.
ket }

If 
NOT EXISTS {drawerNOREQ
    
Echo "Destination directory not found"
    
Skip error
Endif

Set dirname `cut "{file}" word=1 separator="."`

Set path `Pathpart ADD {drawer} "$dirname"`

Makedir $path

LAB error
Unset dirname
Unset path


You might get better control by writing a C language utility that uses xadmaster.library to check for a "container" directory, create a directory if necessary and extract the archive with xadmaster.library.

_________________
Amiga X1000 with 2GB memory & OS 4.1FE + Radeon HD 5450

   Report Go to top

Re: Help with Arexx Script
Just popping in
Joined:
2008/10/18 10:25
From Auckland, New Zealand
Posts: 58
Thank you for the replies. This is what I've landed on.

/* Create Drawer V2*/ 

Parse Arg Args 

IF Left(Args,1)='"' THEN Parse Var Args '"'File'" 'Drawer 
ELSE Parse Var Args File' 'Drawer 

Drawer
=Strip(Drawer,,'"'
chars length(File)
newdir left(File,chars-4)
newdir2 space(newdir,1,'_')

address command

cd Drawer
makedir newdir2
Exit


Is also replaces the spaces with underscores.

@xenic

I've thought about expanding it so it checks that it's an archive, checks whether or not is has an existing directory, and even launching unarc to finish the job.

I don't know C though.

   Report Go to top

Re: Help with Arexx Script
Just can't stay away
Joined:
2006/11/24 18:52
From Gloucestershire, UK.
Posts: 1141
@daveyw

just for a quick comparison, here is a python script to do the same thing.

This method will create a complete dest path recursivly and if you cd to the archive drawer before running the script and uncomment the path and unarc lines it will extract the archive.

There is a simple check of the archive suffix, add more to line 7 if you want to. gzip, bzip etc. are covered by the 'zip' entry so no need to add them.

#!C:Python
#$VER:CreateDrawer.py V0.2 (19-09-2018)

import ossys
legal 
= (':','/')
#path = os.getcwd()
suffix = ('lha','lzx','zip','7z','rar','tar')

numargs len(sys.argv)
if 
numargs <> : exit()

arc sys.argv[1]
arc arc.lower()
if 
not arc.endswith(suffix):
    print 
"Unknown archive suffix, add to line 7 if you are sure it's an archive."
    
exit()

dest sys.argv[2]
if 
dest.endswith(legal):
    
newdest dest+arc[:-4]
else:
    
newdest dest+"/"+arc[:-4]

try:
    
os.makedirs(newdest)
except OSError:
    
# Destination drawer already exists.
    
pass

#os.system('appdir:unarc ' + path + arc + ' ' + newdest + '/' + ' AUTO')
exit()


Edit:
Added archive check and unarc stuff and fixed a few typos.

If you cut'n'paste this make sure the indentation is kept, all indented lines start with a single tab that will have been changed to a space by the site. a single space will still work but a tab makes it easier to read.


Edited by Severin on 2018/9/19 4:12:10
Edited by Severin on 2018/9/19 4:13:12
Edited by Severin on 2018/9/19 4:14:51
Edited by Severin on 2018/9/19 4:16:11
Edited by Severin on 2018/9/19 4:41:09
Edited by Severin on 2018/9/19 4:47:49
Edited by Severin on 2018/9/19 4:51:05
Edited by Severin on 2018/9/19 23:59:32
_________________
Amiga user since 1985
AOS4, A-EON, IBrowse & Alinea Betatester

Ps. I hate the new amigans website. <shudder>
   Report Go to top

Re: Help with Arexx Script
Just can't stay away
Joined:
2008/1/6 17:56
From Pennsylvania, USA
Posts: 1280
@Severin
It may look like the tabs are replaced by spaces but it's actually replacing the tabs with 0xA0 (160 decimal). I can open a Hex window in Turbotext and see what those blank spaces really are. Python might ignore those characters but if it's C code, GCC chokes on those characters. I just perform a "Find & Change" on those characters in Turbotext.


_________________
Amiga X1000 with 2GB memory & OS 4.1FE + Radeon HD 5450

   Report Go to top

Re: Help with Arexx Script
Just can't stay away
Joined:
2006/11/24 18:52
From Gloucestershire, UK.
Posts: 1141
@xenic

I've edited the script again and replaced the tabs/0xA0 chars with 4 spaces, it should just copy'n'paste now.

_________________
Amiga user since 1985
AOS4, A-EON, IBrowse & Alinea Betatester

Ps. I hate the new amigans website. <shudder>
   Report Go to top

Re: Help with Arexx Script
Just popping in
Joined:
2008/10/18 10:25
From Auckland, New Zealand
Posts: 58
Hmm, I get
File "python:scripts/CreateDrawer.py"line 2
SyntaxError
Non-ASCII character 'xa0' in file python:scripts/CreateDrawer.py on line 2but no encoding declaredsee http://www.python.org/peps/pep-0263.html for details

So I guess there's still a copy paste problem.

   Report Go to top

Re: Help with Arexx Script
Just can't stay away
Joined:
2008/1/6 17:56
From Pennsylvania, USA
Posts: 1280
@daveyw
It appears that most of the tabs & spaces in a "code" block are replaced by the 0xA0 code. It's ironic that indentation can only be preserved by using a code block but copying text from a code block won't compile

If you want to copy & test most program code from an Amigans code block, you will need to find & replace 0xA0 codes with a capable text editor or a HEX editor like FileX from OS4Depot.


_________________
Amiga X1000 with 2GB memory & OS 4.1FE + Radeon HD 5450

   Report Go to top

Re: Help with Arexx Script
Just can't stay away
Joined:
2006/11/24 18:52
From Gloucestershire, UK.
Posts: 1141
@daveyw

Try this version... Paste it into an something like notepad and do a search and replace to replace the $'s With spaces.

#!C:Python
#$VER:CreateDrawer.py V0.2 (19-09-2018)

import os, sys
legal 
= (':','/')
#path = os.getcwd()
suffix = ('lha','lzx','zip','7z','rar','tar')

numargs = len(sys.argv)
if numargs <> 3 : exit()

arc = sys.argv[1]
arc = arc.lower()
if not arc.endswith(suffix):
$$$
$print "Unknown archive suffix, add to line 7 if you are sure it's an archive."
$$$$exit()

dest = sys.argv[2]
if dest.endswith(legal):
$$$
$newdest = dest+arc[:-4]
else:
$$$
$newdest = dest+"/"+arc[:-4]

try:
$$$
$os.makedirs(newdest)
except OSError:
$$$$
# Destination drawer already exists.
$$$$pass

#os.system('appdir:unarc ' + path + arc + ' ' + newdest + '/' + ' AUTO')
exit()


_________________
Amiga user since 1985
AOS4, A-EON, IBrowse & Alinea Betatester

Ps. I hate the new amigans website. <shudder>
   Report Go to top





[Advanced Search]


Powered by XOOPS 2.0 © 2001-2016 The XOOPS Project