20 August 2011, 01:11 | #1 |
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? |
20 August 2011, 08:27 | #2 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,369
|
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. |
20 August 2011, 10:01 | #3 | |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 7,026
|
Quote:
Code:
list >ram:script "<directory>" files lformat="<your_command> *"%p%n*"" execute ram:script 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" |
|
20 August 2011, 14:27 | #4 |
Registered User
Join Date: Feb 2004
Location: Valby, Denmark
Age: 48
Posts: 90
|
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. |
21 August 2011, 02:23 | #5 |
Posts: n/a
|
Thomas, that worked like a charm!
Thanks!!! By the way, I found AmigaPython which should do the trick as well. |
08 January 2020, 23:06 | #6 |
Registered User
Join Date: Mar 2018
Location: Austria
Posts: 617
|
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 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 |
08 January 2020, 23:45 | #7 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,307
|
The list command has an "ALL" option which recursively scans subdirectories as well.
|
09 January 2020, 00:42 | #8 |
Registered User
Join Date: Mar 2018
Location: Austria
Posts: 617
|
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) |
09 January 2020, 08:35 | #9 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 7,026
|
list all files p=foo
|
09 January 2020, 13:00 | #10 |
Registered User
Join Date: Dec 2018
Location: UK
Posts: 1,716
|
When I was previously looking for a foreach command I found:
http://aminet.net/package/util/cli/finkelshelltoo |
09 January 2020, 22:15 | #11 |
Registered User
Join Date: Mar 2018
Location: Austria
Posts: 617
|
Hey guys,
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 Code:
list >ram:script1 all files p=name1 lformat="protect *"%p%n*" +s" |
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 |
|
|