title: Rudimentary File Explorer Using Dialog Boxes with FSELECT: Bash
body: <p>I'm trying to do a rudimentary file explorer, as the title says. What I want to do is present the user with a dialog box that allows them to select a file, in this case, a .rar file, but I want them to be able to select the directory where they put the files. Each of them tend to name the directories in which the put these .rar files in a different way, so that's why I want to allow them to navigate between directories using the dialog box.</p>
  
  <p>So far I've come up with this:</p>
  
  <pre><code>#!/bin/bash
  
  # select a file with a dialog box
  # save it in FILE
  
  # If the user picks another directory, show the content of the new directory
  # The script must keep iterating between directories until the correct files
  # are chosen. This must be done recursively.
  
  FILE=$(dialog --clear --title "File Viewer" --stdout \
         --title "Select a file"\
         --fselect /recursos/ 14 58)
  
  # Here I try to keep iterating between directories
  while [ -d "$FILE" ]
  do
    # If the user picks a directory
    if [ -d "$FILE" ]
    then       
      cd "$FILE"  # Change path to that directory
      DIR=$PWD    # Save the new path
      FILE=""     # Clear the selection
      dialog --clear   # Destroy previous dialog box
    else
      echo "Error."
      exit -1
    fi
  
    # Show a new dialog and allow a new selection
    FILE=$(dialog --clear --title "File Viewer" --stdout \
           --title "Select a file"\
           --fselect "$DIR" 14 58)
           echo "Value of $FILE inside the while"
           exit -1   # Exit
  done
  
  # Print the name of the file
  echo $FILE
  </code></pre>
  
  <p>I use the forced exit inside the while loop, because I want to test the values of $FILE, anyways, it's not working as intended. I haven't found examples of how to iterate between directories. I can't use Zenity or any other visual UIs as the server I'm working on has no Internet and I can't download new features or anything to the OS. Also, I can't use --dselect as an option with the Dialog, I don't know why, so what you see it's what I can work with.</p>
  
  <p>Any idea on how this can be done?</p>
  
  <p><strong>Edit:</strong> </p>
  
  <p>Ok, here's what I wanna do. Sometimes, the guys at my work receive some files, they're are compressed as .rar files. They put these files in a folder and then they name the directory after the date they arrive, let's say JUN30 or something. But they name the folders as they please, and they often do, they don't follow any rules in naming these directories. </p>
  
  <p>I want to make a script that allows them to navigate to the folder where they put these compressed files, select the files, and once they press OK, the program will execute a series of steps that are done after those files are uncompressed.</p>
  
  <p>Allowing the users to type in the folder where they put the compressed files doesn't seem to be viable, since working visually would be easier. You know, I don't want the users to be able to mess around too much. It's necessary to do this, since uncompressing the files is only the first step of many, and I was assigned with automating a lot of tasks.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I changed my code to work a bit differently since the old way wasn't doing what I wanted, here's what I have so far:</p>
  
  <pre><code>#!/bin/bash
  
  function fileChooser(){
    local __DIR=$1
    local __RESULT=$(dialog --clear --title "Choose Directory" --stdout \
                     --title "Choose File"\
                     --fselect $__DIR 14 58)
  
    echo $__RESULT
  }
  
  RESULT=$( fileChooser /recursos/ )
  
  while [ -d "$RESULT" ]
  do
    RESULT=$( fileChooser "$RESULT/" )
  done
  
  # Print selection
  echo $RESULT
  </code></pre>
  
  <p>Any suggestions on what I should improve to make my code as fail safe as possible? The intention is that the users should be able to execute a bunch of automated tasks without much intervention on their part other than picking the directory with the files.</p>