2
votes

I am trying to retrieve the files and directories in Qt using the QDir Filter. Based on the user input from the command line I plan to set the appropriate filters and retrieve the corresponding files.

User Input Eg: ./Retrieve -d C:/Sample -h

would retrieve me all the files including hidden files in the directory C:/Sample. I plan to give a host of other options like

-h (for hidden files) -r (for readonly files) -s (for system files)

currently my code is something like

QDir::entryList(QDir::Dirs |QDir::NoDotAndDotDot | QDir::Hidden)

If I want to fetch even the system files I need to add just the Qdir::system filter . How can I append this to the existing filters I would have already mentioned. My question is How do I add these filters to the QDir function entry List by having simple online code but build up the filters by looking at the user input?

1

1 Answers

3
votes

It's a three step process:

  1. Define the flags that are the same regardless of user input, call it filters or something.
  2. Iterate over the command line arguments and, when certain arguments are found, do a logical-OR of the appropriate QDir::Filter flag with filters
  3. Keep going until all the cmdline arguments are dealt with.

filters now has all the filters the user requested.