Loading ...
Sorry, an error occurred while loading the content.

Listing a folder contents

Expand Messages
  • jeffonymail
    I want to write a ChipmunkBASIC programme to list the contents of a folder (Macintosh OSX 10.5). Looking at the documentation,it seems that I need to use UNIX
    Message 1 of 5 , Oct 2, 2008
    • 0 Attachment
      I want to write a ChipmunkBASIC programme to list the contents of a
      folder (Macintosh OSX 10.5). Looking at the documentation,it seems
      that I need to use UNIX commands.

      I wrote the following to list the files and folders in my "Documents"
      folder but it instead lists the files in my "Desktop" folder. Why is
      this, and what do I need to change?

      a$=system$("cd ~/Documents")
      print a$

      open "pipe:/bin/ls -l" for input as #1
      while not eof
      input #1, b$
      print b$
      wend
      close #1


      .....Jeff
    • Michel Clasquin-Johnson
      OK, every time you use a sys or system$ statement, a copy of bash is opened in the background. When the command is done, it closes and any changes you have
      Message 2 of 5 , Oct 2, 2008
      • 0 Attachment
        OK, every time you use a sys or system$ statement, a copy of bash is
        opened in the background. When the command is done, it closes and any
        changes you have made are lost. So you start out with the Desktop as
        the working directory, you open bash and cd to Documents, then close
        bash. But the cd is not persistent between bash sessions. The next
        time you open bash via a sys command, you are back to where you started.

        But we can work around this. If you open a terminal and type

        cd ~/Documents/;ls

        you will see that the semicolon acts as if you had written a little
        bash script. it is functionally the same as

        #!/bin/bash
        cd ~/Documents/
        ls

        So now let's try that in Chipmunkese:

        sys("cd ~/Documents/;ls")

        OK, I hope that helps

        On 02 Oct 2008, at 3:46 PM, jeffonymail wrote:

        >
        >
        > I want to write a ChipmunkBASIC programme to list the contents of a
        > folder (Macintosh OSX 10.5). Looking at the documentation,it seems
        > that I need to use UNIX commands.
        >
        > I wrote the following to list the files and folders in my "Documents"
        > folder but it instead lists the files in my "Desktop" folder. Why is
        > this, and what do I need to change?
        >
        > a$=system$("cd ~/Documents")
        > print a$
        >
        > open "pipe:/bin/ls -l" for input as #1
        > while not eof
        > input #1, b$
        > print b$
        > wend
        > close #1
        >
        >
        > .....Jeff
        >
        >
        >
        > ------------------------------------
        >
        > Yahoo! Groups Links
        >
        >
        >

        ---------------------
        Michel Clasquin-Johnson
        e-mail: clasqm@...
        website: http://www.reviewcentral.co.za/




        [Non-text portions of this message have been removed]
      • Jim DeVona
        Alternatively, try open pipe:/bin/ls ~/Documents for input as #1 while not eof input #1, b$ print b$ wend close #1 (You can specify the desired path as an
        Message 3 of 5 , Oct 2, 2008
        • 0 Attachment
          Alternatively, try

          open "pipe:/bin/ls ~/Documents" for input as #1
          while not eof
          input #1, b$
          print b$
          wend
          close #1

          (You can specify the desired path as an argument to ls.)

          Jim

          On Thu, Oct 2, 2008 at 10:40 AM, Michel Clasquin-Johnson
          <clasqm@...> wrote:
          > OK, every time you use a sys or system$ statement, a copy of bash is
          > opened in the background. When the command is done, it closes and any
          > changes you have made are lost. So you start out with the Desktop as
          > the working directory, you open bash and cd to Documents, then close
          > bash. But the cd is not persistent between bash sessions. The next
          > time you open bash via a sys command, you are back to where you started.
          >
          > But we can work around this. If you open a terminal and type
          >
          > cd ~/Documents/;ls
          >
          > you will see that the semicolon acts as if you had written a little
          > bash script. it is functionally the same as
          >
          > #!/bin/bash
          > cd ~/Documents/
          > ls
          >
          > So now let's try that in Chipmunkese:
          >
          > sys("cd ~/Documents/;ls")
          >
          > OK, I hope that helps
          >
          > On 02 Oct 2008, at 3:46 PM, jeffonymail wrote:
          >
          >>
          >>
          >> I want to write a ChipmunkBASIC programme to list the contents of a
          >> folder (Macintosh OSX 10.5). Looking at the documentation,it seems
          >> that I need to use UNIX commands.
          >>
          >> I wrote the following to list the files and folders in my "Documents"
          >> folder but it instead lists the files in my "Desktop" folder. Why is
          >> this, and what do I need to change?
          >>
          >> a$=system$("cd ~/Documents")
          >> print a$
          >>
          >> open "pipe:/bin/ls -l" for input as #1
          >> while not eof
          >> input #1, b$
          >> print b$
          >> wend
          >> close #1
          >>
          >>
          >> .....Jeff
          >>
          >>
          >>
          >> ------------------------------------
          >>
          >> Yahoo! Groups Links
          >>
          >>
          >>
          >
          > ---------------------
          > Michel Clasquin-Johnson
          > e-mail: clasqm@...
          > website: http://www.reviewcentral.co.za/
          >
          > [Non-text portions of this message have been removed]
          >
          >



          --
          EvoS Project Coordinator
          Binghamton University
          Science 3 Room 361
          Cell phone: 607-221-2165
        • jeffonymail
          Thanks, Michel. Thanks for the info about bash and why my change directory command didn t stick. Now I understand the process better. I didn t know I could
          Message 4 of 5 , Oct 2, 2008
          • 0 Attachment
            Thanks, Michel.

            Thanks for the info about bash and why my change directory command
            didn't stick. Now I understand the process better.

            I didn't know I could stack UNIX commands using a semicolon. That's
            very useful and I will remember it for the future.

            Your solution fixes my problem but output is to the screen so I am
            going to use Jim's solution to send the output to a pipe.

            Thanks.

            .....Jeff

            --- In chipmunkbasicforum@yahoogroups.com, Michel Clasquin-Johnson
            <clasqm@...> wrote:
            >
            > OK, every time you use a sys or system$ statement, a copy
            > of bash is opened in the background. When the command is
            > done, it closes and any changes you have made are lost. So
            > you start out with the Desktop as the working directory,
            > you open bash and cd to Documents, then close bash. But
            > the cd is not persistent between bash sessions. The next
            > time you open bash via a sys command, you are back to
            > where you started.
            >
            > But we can work around this. If you open a terminal and type
            >
            > cd ~/Documents/;ls
            >
            > you will see that the semicolon acts as if you had written
            > a little bash script. it is functionally the same as
            >
            > #!/bin/bash
            > cd ~/Documents/
            > ls
            >
            > So now let's try that in Chipmunkese:
            >
            > sys("cd ~/Documents/;ls")
            >
            > OK, I hope that helps
          • jeffonymail
            Hi, Jim. Thanks for your reply. I tried adding the directory name to the ls command and it worked as you suggested. I had some parameters after the ls command
            Message 5 of 5 , Oct 2, 2008
            • 0 Attachment
              Hi, Jim.

              Thanks for your reply.

              I tried adding the directory name to the ls command and it worked as
              you suggested. I had some parameters after the ls command (-l -p -T)
              and found that the directory name had to go after the parameters.

              My programme is now working fine. Next is to try recursive pipes for
              sub-directories.

              .....Jeff

              --- In chipmunkbasicforum@yahoogroups.com, "Jim DeVona"
              <jim.devona@...> wrote:
              >
              > Alternatively, try
              >
              > open "pipe:/bin/ls ~/Documents" for input as #1
              > while not eof
              > input #1, b$
              > print b$
              > wend
              > close #1
              >
              > (You can specify the desired path as an argument to ls.)
              >
              > Jim
            Your message has been successfully submitted and would be delivered to recipients shortly.