Search code examples
linuxshellzenity

Zenity command for multiple file filtering


I tried some Zenity command for file filtering in my java program.

zenity --file-selection --file-filter=""*.ogg" "*.wav" "*.aac""   

and

zenity --file-selection --multiple --file-filter=*.gif *.jpeg *.jpg

But these are not worked properly . insted of giving the all filtered file it only give the first file type given in the comment ,thant means;

zenity --file-selection --multiple --file-filter=*.gif *.jpeg *.jpg 

in these, it given back only the .gif file as the output) .


Solution

  • Could you try something like this;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    
    public class RunBash {
    
        public static void main(String[] args) {
              String cmd = "zenity --file-selection --file-filter=\"\"*.gif\" \"*.jpeg\" \"*.jpg\"\"";
    
                try {
                    Process proc = Runtime.getRuntime().exec(new String[] {"/bin/bash", "-c", cmd});
                    BufferedReader read = new BufferedReader(new InputStreamReader(proc.getInputStream()));
                    try {
                        proc.waitFor();
                    } catch (InterruptedException e) {
                        System.out.println(e.getMessage());
                    }
                    while (read.ready()) {
                        System.out.println(read.readLine());
                    }
                } catch (IOException e) {
                    System.out.println(e.getMessage());
                }
        }
    }