Unsolved qt file search and open
-
for Linux if I have file under /home/test/test.txt how would I search test.txt under /home/test and open it? using Qdir or Qfileinfo?
-
Hi,
Depending on your goal, using the find command through QProcess might be more efficient.
Otherwise, using QDirIterator is likely more what you want.
-
As @SGaist mentioned, there are a couple of ways of doing this and it depends on your goal. If it's simply to locate the file once then the QProcess route is probably adequate, although any spawned command process must be treated as a potential security risk and spawning subprocesses is a heavier weight solution. If you want to do it programmatically then you recursively call a method using elements of QDirIterator. This is comp-sci 101 stuff: recursive tree searches.
-
This post is deleted! -
I am not sure I am following your question. QFileInfo returns information about a file so you can get what you want. Or are you thinking about some sort of filtering ?
-
sry. i'm try to find certain file with extension. for example
under c:/tmp I want to get the file name for any file with .txt extension. if there is no file with *.txt then return false, but if there is files with .txt I like to get that files info (name etc).
-
Returning either false or a list of file names sounds fishy. You should rather handle the case of an empty list. It will be cleaner.
-
ok thanks, but i'm guessing use QDirIterator and Qfileinfo is the way to go?
-
For your purpose, it looks like it yes.