Amiga.org

Amiga computer related discussion => Amiga Tutorials => Topic started by: sim085 on October 13, 2009, 11:56:20 AM

Title: Looping through all directories of a partition?
Post by: sim085 on October 13, 2009, 11:56:20 AM
Hello,

I am new to scripting and I was wondering if anyone could help me achieve this. Is there a way to create a loop that loops within every directory of a partition? For example - can I make a loop that would first traverse all directories of System: and then all directories in System:C, then all sub-directories of System:C, etc.

Regards,
Sim085
Title: Re: Looping through all directories of a partition?
Post by: jj on October 13, 2009, 11:59:13 AM
is this connected to changing icons ?
Title: Re: Looping through all directories of a partition?
Post by: sim085 on October 13, 2009, 12:04:10 PM
Quote from: JJ;525784
is this connected to changing icons ?


Yes - but I started a new thread because it is more related to scripting rather then changing icons (which I know how to using CLI now). I am trying to write a script that can change for everyone rather then only myself and my set-up. At the moment I am trying to backup the original icons and then I will move to the next step of copy new icons from a source directory. I will also write a restore script so that one can change from one set-up to another with relative easiness. ... although I wonder who may need this apart me :)
Title: Re: Looping through all directories of a partition?
Post by: jj on October 13, 2009, 01:15:19 PM
Will the cli program allow you to use wildcards ?
 
So you could use #?.info for instance.
 
I am not sure how you would loop through all the directories to do this though.  I suspect you would need to supply a definite list
Title: Re: Looping through all directories of a partition?
Post by: Thomas on October 13, 2009, 01:27:13 PM
If it does not allow wildcards, you can use the List command to call the program for each file:

Code: [Select]

list >ram:scriptfile work:dirname all files p=#?.info lformat="changeicon *"%p%m*" xyz"
execute ram:scriptfile
Title: Re: Looping through all directories of a partition?
Post by: jj on October 13, 2009, 01:29:58 PM
Quote from: Thomas;525790
If it does not allow wildcards, you can use the List command to call the program for each file:
 
Code: [Select]
list >ram:scriptfile work:dirname all files p=#?.info lformat="changeicon *"%p%m*" xyz"
execute ram:scriptfile

 
I was going to suggest something using pipes but wasnt sure how you would then call the program for each one.
 
Good to learn some of this stuff.
Title: Re: Looping through all directories of a partition?
Post by: sim085 on October 13, 2009, 01:35:19 PM
Quote from: JJ;525789
Will the cli program allow you to use wildcards?
I just tried that out but does not seem to work.
Quote from: Thomas;525790
If it does not allow wildcards, you can use the List command to call the program for each file:
Thanks :) I'll see how that peace of code works.

So it seems that script files do not support for-loops and if-statements right?
Title: Re: Looping through all directories of a partition?
Post by: meega on October 13, 2009, 02:31:07 PM
Quote from: sim085;525794
So it seems that script files do not support for-loops and if-statements right?

Check out the startup-sequence... see if there's an If in there. ;)

For has also been implemented by third parties in a number of instances, but not in the standard Workbench/CLI/Shell iirc.
Title: Re: Looping through all directories of a partition?
Post by: sim085 on October 13, 2009, 03:06:19 PM
Quote from: meega;525804
Check out the startup-sequence... see if there's an If in there. ;)

For has also been implemented by third parties in a number of instances, but not in the standard Workbench/CLI/Shell iirc.


Thanks :) Yes there is an example in there! I'll see how I can use that for my script.
Title: Re: Looping through all directories of a partition?
Post by: sim085 on October 13, 2009, 06:15:28 PM
Is there a way how I can insert a return line in there? I need to insert some if statements in the generated script and I cannot do that in a single line :(
Title: Re: Looping through all directories of a partition?
Post by: sim085 on October 13, 2009, 06:36:23 PM
Hi, sorry to bring this up again, but does anyone know how to check if a file is a directory or not?
Title: Re: Looping through all directories of a partition?
Post by: MozzerFan on October 13, 2009, 07:00:30 PM
Quote from: sim085;525846
Hi, sorry to bring this up again, but does anyone know how to check if a file is a directory or not?

In Thomas example script, he uses the "files" parameter for the list command. This will only give a list of all files in a directory.
 
The "dirs" parameter for the list command will only give a list of all directories.
Title: Re: Looping through all directories of a partition?
Post by: sim085 on October 13, 2009, 07:06:18 PM
Quote from: MozzerFan;525849
The "dirs" parameter for the list command will only give a list of all directories.

What I meant is if there is a way to check if for example Sys:A is a directoy or not. Something as follows:

Code: [Select]
IF Sys:A IS DIRECTORY
   ; do something
EndIF
Obviously the above code is not correct. However is there anything that can help me achieve the same?
Title: Re: Looping through all directories of a partition?
Post by: sim085 on October 14, 2009, 07:57:36 AM
Ok, I managed to do what I want using Thomas previous example and MozzerFan information about 'dirs'. I have completed by first script which takes a backup of all the current icons installed on a particular partition :) Now I'll move to the next step so that I can make an installation script! These scripts are nothing special, but when ready I'll make them available for anyone who would like to use it in any way.