English Amiga Board

English Amiga Board (https://eab.abime.net/index.php)
-   support.Other (https://eab.abime.net/forumdisplay.php?f=74)
-   -   for..each statement in CLI (https://eab.abime.net/showthread.php?t=60638)

pieter1976 20 August 2011 01:11

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?

jotd 20 August 2011 08:27

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.

thomas 20 August 2011 10:01

Quote:

Originally Posted by pieter1976 (Post 773296)
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"

Zack 20 August 2011 14:27

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. :)

pieter1976 21 August 2011 02:23

Thomas, that worked like a charm!

Thanks!!!

By the way, I found AmigaPython which should do the trick as well.

Nightshft 08 January 2020 23:06

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 :)

Thomas Richter 08 January 2020 23:45

The list command has an "ALL" option which recursively scans subdirectories as well.

Nightshft 09 January 2020 00:42

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)

thomas 09 January 2020 08:35

list all files p=foo

solarmon 09 January 2020 13:00

When I was previously looking for a foreach command I found:

http://aminet.net/package/util/cli/finkelshelltoo

Nightshft 09 January 2020 22:15

Hey guys,

Quote:

Originally Posted by thomas (Post 1370394)
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! :great


All times are GMT +2. The time now is 19:57.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.

Page generated in 0.04724 seconds with 11 queries