Welcome, Guest. Please login or register.

Author Topic: Looping through all directories of a partition?  (Read 3061 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline sim085Topic starter

  • Hero Member
  • *****
  • Join Date: Aug 2008
  • Posts: 958
    • Show only replies by sim085
Looping through all directories of a partition?
« 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
 

Offline jj

  • Lifetime Member
  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 4051
  • Country: wales
  • Thanked: 2 times
  • Gender: Male
    • Show only replies by jj
Re: Looping through all directories of a partition?
« Reply #1 on: October 13, 2009, 11:59:13 AM »
is this connected to changing icons ?
“We don't stop playing because we grow old; we grow old because we stop playing.” - George Bernard Shaw

Xbox Live: S0ulA55a551n2
 
Registered MorphsOS 3.13 user on Powerbook G4 15"
 

Offline sim085Topic starter

  • Hero Member
  • *****
  • Join Date: Aug 2008
  • Posts: 958
    • Show only replies by sim085
Re: Looping through all directories of a partition?
« Reply #2 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 :)
 

Offline jj

  • Lifetime Member
  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 4051
  • Country: wales
  • Thanked: 2 times
  • Gender: Male
    • Show only replies by jj
Re: Looping through all directories of a partition?
« Reply #3 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
“We don't stop playing because we grow old; we grow old because we stop playing.” - George Bernard Shaw

Xbox Live: S0ulA55a551n2
 
Registered MorphsOS 3.13 user on Powerbook G4 15"
 

Offline Thomas

Re: Looping through all directories of a partition?
« Reply #4 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

Offline jj

  • Lifetime Member
  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 4051
  • Country: wales
  • Thanked: 2 times
  • Gender: Male
    • Show only replies by jj
Re: Looping through all directories of a partition?
« Reply #5 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.
“We don't stop playing because we grow old; we grow old because we stop playing.” - George Bernard Shaw

Xbox Live: S0ulA55a551n2
 
Registered MorphsOS 3.13 user on Powerbook G4 15"
 

Offline sim085Topic starter

  • Hero Member
  • *****
  • Join Date: Aug 2008
  • Posts: 958
    • Show only replies by sim085
Re: Looping through all directories of a partition?
« Reply #6 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?
 

Offline meega

  • Hero Member
  • *****
  • Join Date: Jul 2006
  • Posts: 952
    • Show only replies by meega
Re: Looping through all directories of a partition?
« Reply #7 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.
:)
 

Offline sim085Topic starter

  • Hero Member
  • *****
  • Join Date: Aug 2008
  • Posts: 958
    • Show only replies by sim085
Re: Looping through all directories of a partition?
« Reply #8 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.
 

Offline sim085Topic starter

  • Hero Member
  • *****
  • Join Date: Aug 2008
  • Posts: 958
    • Show only replies by sim085
Re: Looping through all directories of a partition?
« Reply #9 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 :(
 

Offline sim085Topic starter

  • Hero Member
  • *****
  • Join Date: Aug 2008
  • Posts: 958
    • Show only replies by sim085
Re: Looping through all directories of a partition?
« Reply #10 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?
 

Offline MozzerFan

  • Hero Member
  • *****
  • Join Date: Mar 2005
  • Posts: 607
  • Country: 00
    • Show only replies by MozzerFan
Re: Looping through all directories of a partition?
« Reply #11 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.
 

Offline sim085Topic starter

  • Hero Member
  • *****
  • Join Date: Aug 2008
  • Posts: 958
    • Show only replies by sim085
Re: Looping through all directories of a partition?
« Reply #12 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?
« Last Edit: October 13, 2009, 07:08:34 PM by sim085 »
 

Offline sim085Topic starter

  • Hero Member
  • *****
  • Join Date: Aug 2008
  • Posts: 958
    • Show only replies by sim085
Re: Looping through all directories of a partition?
« Reply #13 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.