I have done lots of searching about this, but I cannot seem to find an answer that satisfies my needs. I want a simple way to search for two file types or more (e.g. *.mp3, *.aac, *.pdf, etcetera.) I understand that the Linux command find does this via terminal searches, but I want a program with a GUI for this particular need. I have tried Nemo File Manager's built in search, the same goes for Caja, PCManFM, and others. I have also experimented with catfish and searchmonkey. I just can't seem to get any productive results. Any help is highly appreciated. Thanks in advance.
Unless you really need the speed of C, I'd recommend a script language (Ruby, Python or similar). You'll be able to do sophisticated tasks without the tediousness of C (no flames please).
Here's what I'd do:
Use the Python-GTK interface to make the GUI: You only need 4 widgets: A Gtk.Window, a Gtk.VBox (to store the next two items), A Gtk.Entry to enter the file types, and a Gtk.TreeView to show the results
From Python you can easily combine the list from the Gtk.Entry and the command
find+ options + file types, to get the list. (You can execute the
Checkcall returns the list, which you can then show in the Gtk.TreeView.
If you'd like to learn Python, there are plenty excellent tutorials on the 'net. This is the official tutorial on Python's site. The learnPython site is very interesting, as you can even try out your programs. This tutorial should give you all you need to use the GUI stuff in Python with plenty of examples.
A script language like Python is ideal to solve problems like the one you describe.
EDIT I had some time, and thought that it wouldn't be bad to have a compact GUI finder. Below is a working code. Yes, it's longer than 20 lines, mainly because I constructed the entire GUI in code. If I used Glade (a GUI designer), the code would be halved. Also, I added a dialog to select the root of the search.
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # test_finder.py # # Copyright 2016 John Coppens <email@example.com> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. # # from gi.repository import Gtk import os, fnmatch class MainWindow(Gtk.Window): def __init__(self): super(MainWindow, self).__init__() self.connect("destroy", lambda x: Gtk.main_quit()) self.set_size_request(600, 400) vbox = Gtk.VBox() # Pattern entry self.entry = Gtk.Entry() self.entry.connect("activate", self.can't open file 'pyfind.py'on_entry_activated) # Initial path selection self.path = Gtk.FileChooserButton(title = "Select start path", action = Gtk.FileChooserAction.SELECT_FOLDER) self.path.set_current_folder(".") # The file list + a scroll window self.list = self.make_file_list() scrw = Gtk.ScrolledWindow() scrw.add(self.list) vbox.pack_start(self.entry, False, False, 0) vbox.pack_start(self.path, False, False, 0) vbox.pack_start(scrw, True, True, 0) self.add(vbox) self.show_all() def make_file_list(self): self.store = Gtk.ListStore(str, str) filelist = Gtk.TreeView(model = self.store, enable_grid_lines = True) renderer = Gtk.CellRendererText() col = Gtk.TreeViewColumn("Files:", renderer, text = 0, sizing = Gtk.TreeViewColumnSizing.AUTOSIZE) filelist.append_column(col) col = Gtk.TreeViewColumn("Path:", renderer, text = 1) filelist.append_column(col) return filelist def on_entry_activated(self, entry): self.store.clear() patterns = entry.get_text().split() path = self.path.get_filename() for root, dirs, files in os.walk(path): for name in files: for pat in patterns: if fnmatch.fnmatch(name, pat): self.store.append((name, root)) def run(self): Gtk.main() def main(args): mainwdw = MainWindow() mainwdw.run() return 0 if __name__ == '__main__': import sys sys.exit(main(sys.argv))
- Check if you have Python3 installed (
python -V). If not, install it.
- Save the above program as, say
- Make it executable
chmod 755 pyfind.py
- Execute it with
- Type in the filter, press Enter.
- If you change the path, repeat 1 (can avoid that by using a signal from the FileChooserButton, if wanted)
I'm not sure what's happening in you case, but the log says python3 is not finding the pyfind.py file. You can make the file directly executable:
Change the first line of the code to:
To make the above file executable, do (in a terminal window, in the directory where pyfind.py is):
chmod 755 pyfind.py
You should then be able to execute the program simply like this (again, in the terminal):