English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System > Coders. Scripting

 
 
Thread Tools
Old 16 September 2017, 07:50   #1
Frankie
Registered User
 
Join Date: Mar 2016
Location: Yes
Posts: 14
AmigaDOS script: Replacing characters and checking if directory is empty

Hi everyone.

A couple of AmigaDOS shell scripting questions:

1. Is it possible to escape a filename or directory name? eg. Instead of "Example#File.txt", it can be escaped to "Example'#File.txt". I can't think of any way of doing string substitution.

2. Is it possible to check if a directory is empty?

Thanks!
Frankie is offline  
Old 16 September 2017, 14:17   #2
daxb
Registered User
 
Join Date: Oct 2009
Location: Germany
Posts: 3,303
1. Use Arexx. Maybe there is a way doing it in DOS but I don`t know.

2. "list Ram:Clipboards/" outputs: Directory "Ram:Clipboards/" is empty. If you examine this you should be able to check for empty dirs. Or use Arexx.
daxb is offline  
Old 16 September 2017, 14:53   #3
emufan
Registered User
 
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
some aminet tools may help:
CheckEmpty V1.4 - Checks if a directory is empty
list of tools matching string.
emufan is offline  
Old 17 September 2017, 17:18   #4
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 4,332
1. You almost wrote the solution yourself. An apostrophe will escape a wildcard character. This I never knew, but the AmigaDOS manual does state it:
http://wiki.amigaos.net/wiki/AmigaOS...DOS_Characters
idrougge is offline  
Old 24 September 2017, 19:40   #5
Frankie
Registered User
 
Join Date: Mar 2016
Location: Yes
Posts: 14
I don't want to use Arexx :P

I'd already messed with listing a directory and checking for output, but things became complicated when the directory didn't exist.

Anywho, CheckEmpty did what I want (thanks emufan!). I'd already checked Aminet for string tools but nothing does exactly what I want, so I wrote it in C

Thanks guys!
Frankie is offline  
Old 29 March 2024, 20:24   #6
pixie
Registered User
 
pixie's Avatar
 
Join Date: May 2020
Location: Figueira da Foz
Posts: 341
Quote:
Originally Posted by Frankie View Post
I don't want to use Arexx :P

I'd already messed with listing a directory and checking for output, but things became complicated when the directory didn't exist.

Anywho, CheckEmpty did what I want (thanks emufan!). I'd already checked Aminet for string tools but nothing does exactly what I want, so I wrote it in C

Thanks guys!
I was trying to check if a given string is either a file or a directory, but I can't get it to work.

I try to do something like this
Code:
ce ce >nil:
if warn
 echo option a
endif
if error
 echo option b
endif
if fail
 echo option c
endif
which gives me "ce failed returncode 10" instead of picking one of the choices
pixie is offline  
Old 29 March 2024, 22:22   #7
Eaglef00t
Registered User
 
Join Date: Dec 2017
Location: US
Posts: 9
Add

FailAt 50

to the top of the script. By default, it is 10.
Eaglef00t is offline  
Old 30 March 2024, 09:35   #8
pixie
Registered User
 
pixie's Avatar
 
Join Date: May 2020
Location: Figueira da Foz
Posts: 341
Quote:
Originally Posted by Eaglef00t View Post
Add

FailAt 50

to the top of the script. By default, it is 10.
It somehow works, still I should have something wrong in my script since it gives me always the same option wether I refer to a file, an empty folder or a folder
pixie is offline  
Old 30 March 2024, 11:02   #9
patrik
Registered User
 
patrik's Avatar
 
Join Date: Jan 2005
Location: Umeå
Age: 43
Posts: 922
Two issues:
1. Running a command will overwrite the result code stored in local env RC from ce. Command for example is If. So the next If checks RC from previous command which is If.
2.WARN matches RC greater or equal to 5, ERROR greater or equal to 10 and so on, so even if 1. Was not an issue, if you got RC 10, it would match the two first If clauses.

Instead, after the ce line, save RC in a local env variable so you can keep the value over several if checks and compare against the exact values you are interested in in the If’s.

Last edited by patrik; 30 March 2024 at 11:15.
patrik is offline  
Old 30 March 2024, 11:53   #10
pixie
Registered User
 
pixie's Avatar
 
Join Date: May 2020
Location: Figueira da Foz
Posts: 341
nice, didn't knew the error code was passed through $rc. It helps a lot
pixie is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
AmigaDos script help liviux76 Coders. Scripting 8 09 November 2017 16:20
Checking for genuine CPUs? Mr.Flibble support.Hardware 0 03 July 2015 21:08
Changing date/timestamp of AmigaDOS directory? rhester72 support.Apps 1 27 May 2015 23:42
AmigaDos script file help. T_hairy_bootson support.Apps 0 07 March 2006 10:15
Checking my Religion Axxy request.Modules 0 04 July 2005 19:22

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 15:31.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.12757 seconds with 15 queries