English Amiga Board


Go Back   English Amiga Board > Support > support.Other

 
 
Thread Tools
Old 20 August 2011, 01:11   #1
pieter1976
 
Posts: n/a
for..each statement in CLI

I'd like to create a CLI batch file doing something like this:

For Each <file> in <directory> Do
{}

But i don't know how.

Anyone?
 
Old 20 August 2011, 08:27   #2
jotd
This cat is no more
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 48
Posts: 3,643
there's no such way

use spat, it's kind of similar: performs a command on a pattern of files

for recursivity, you have to use a recursive dir and rework the output to generate a temp script file that you execute. you can install the amiga version of sed, cut, etc... to help you with the replacements.

clumsy! i dunno about python on the classic amigas, but python just rules compared to all other scripting languages. even perl and bash don't stand a chance against it.

as for stuff i know of, there are implementations of csh and ksh (pdksh). I used the latter but proved kind of instable.
jotd is offline  
Old 20 August 2011, 10:01   #3
thomas
Registered User
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 5,937
Quote:
Originally Posted by pieter1976 View Post
I'd like to create a CLI batch file doing something like this:

For Each <file> in <directory> Do
{}

But i don't know how.

Anyone?

Code:
list >ram:script "<directory>" files lformat="<your_command> *"%p%n*""
execute ram:script
You can put multiple commands into lformat if you use *n as newline character.

For example:

Code:
list >ram:script Work: all dirs lformat="if not exists *"%p%n.info*"*n  copy envarc:Sys/def_drawer.info *"%p%n.info*"*nendif"
thomas is offline  
Old 20 August 2011, 14:27   #4
Zack
Registered User

Zack's Avatar
 
Join Date: Feb 2004
Location: Valby, Denmark
Age: 43
Posts: 67
There are a couple of "foreach" programs on Aminet: http://aminet.net/search?query=foreach that might be useful?

I remember using foreach.lha in some scripts with DirOpus with good results.
Zack is offline  
Old 21 August 2011, 02:23   #5
pieter1976
 
Posts: n/a
Thomas, that worked like a charm!

Thanks!!!

By the way, I found AmigaPython which should do the trick as well.
 
Old 08 January 2020, 23:06   #6
Nightshft
Registered User

Nightshft's Avatar
 
Join Date: Mar 2018
Location: Austria
Age: 44
Posts: 315
Is there any way to do the following:

Code:
For each file named "foo" in this folder and all its subfolders do:
  some dos command like:
  delete the file
  or protect the file rwed
I tried some things including creating a script with "list" and "lformat" but got it working only for the top folder and not the subfolders.

I didn't try the "foreach" programs until now, but I'm not sure they can filter files by name from all subdirectories.
Any ideas how to write this?
Thanks
Nightshft is offline  
Old 08 January 2020, 23:45   #7
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 344
The list command has an "ALL" option which recursively scans subdirectories as well.
Thomas Richter is offline  
Old 09 January 2020, 00:42   #8
Nightshft
Registered User

Nightshft's Avatar
 
Join Date: Mar 2018
Location: Austria
Age: 44
Posts: 315
Thanks Thomas. Yes, that's what I thought too.
But "list foo all" lists all files of the directories named foo.
What I'd need: List all files named foo in all the subdirectories.
(Example case: 200 directories, some of them contain the file foo)
Nightshft is offline  
Old 09 January 2020, 08:35   #9
thomas
Registered User
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 5,937
list all files p=foo
thomas is offline  
Old 09 January 2020, 13:00   #10
solarmon
Registered User

solarmon's Avatar
 
Join Date: Dec 2018
Location: UK
Posts: 760
When I was previously looking for a foreach command I found:

http://aminet.net/package/util/cli/finkelshelltoo
solarmon is offline  
Old 09 January 2020, 22:15   #11
Nightshft
Registered User

Nightshft's Avatar
 
Join Date: Mar 2018
Location: Austria
Age: 44
Posts: 315
Hey guys,

Quote:
Originally Posted by thomas View Post
list all files p=foo
did the trick. Together with the lformat syntax from post 3.

For further reference:
Create a script with "command path/name" of all filtered filenames (including subfolders):
Code:
list >ram:script1 all files p=name1 lformat="command *"%p%n*""
execute ram:script1
So with this I could add the "s" flag to all the 407 files (in an equal number of subfolders) affected.
Code:
list >ram:script1 all files p=name1 lformat="protect *"%p%n*" +s"
Worked perfectly. Thanks a lot!
Nightshft 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
SECTION statement and the CHIP/FAST attribute Apollo Coders. Asm / Hardware 3 15 June 2013 18:18
Amikit and CLI BanisterDK support.WinUAE 2 16 September 2012 12:10
CLI help DeafDaz request.Other 3 10 August 2011 01:16
Hyperion Statement on litigation with Amiga Inc. Ultron News 2 02 May 2007 11:06

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 08:09.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.07922 seconds with 13 queries