Select folders with file(s) matching a pattern?

Is there a way to select all folder that have file(s) that match a regex pattern?

In other words, if I'm looking at the directory

c:\mydir

.. that has the following sub-dirs:

c:\mydir\one
c:\mydir\two
c:\mydir\three
c:\mydir\four
c:\mydir\five

I would like to be able to select folders "two" and "four" as both of them contain a file "manual.pdf". Preferably the selection would be recursive so that both folders "two" and "four" would be selected even though "four" has the file "manual.pdf" in a subfolder:

c:\mydir\two\manual.pdf
c:\mydir\four\otherdir\manual.pdf

Thanks for any advice!

you can use Flat View mode (3 different possibilities, i'd recommend Group) and then use View Filters, then Select. no need for regex :wink:

Did you look at the Advanced tab in Search?

Looks pretty comprehensive to me.

Ctrl+F
Advanced
Use Regular Expression

Apologies if you have been there already. If that doesn't suit then maybe you need to say why. Or I just don't understand the question.

Maybe it is the folders you are looking for rather than the files.

Thanks for the replies.

I've looked (and often use) the Advanced Find regex option, and tried out the Flat View (which I had forgotten)... but I'm not sure if either of these are of help in what I'm trying to accomplish.

The goal is to be able to move any top level folders (and all of their contents) to a different location if even one PDF file exists in the directory structure underneath. So in case of my example I'd like to be able to select directories "two" and "four" in order to move them elsewhere. Those top level directories contain other files as well, and I'd like to keep their file/folder structure intact while moving them to a different location. If I use Advanced Find with regex or Flat View, I can certainly select all the PDF-files in the folder structure, but if I drag the selected files into a different folder, they're moved out of their respective top level folder structures which I don't want.

It may be that I have to write a batch file to do this, but I first wanted to see if this is something I'd be able to do in Directory Opus since the need to do this comes up frequently.

May someone else elaborate on a regex solution, lemme talk about my personal solution (because i dont know what regex is lol):
I've tested my suggested solution on a huge set of files. I like Dopus because i can devise straight-forward strategies to do file managing tasks without writing a batch file or programming a highly-specialized button. So here the most straight-forward method is using Grouped (Flat View Mode), and then filter the view with "manua", and you will see a listing of indented folders. Some of them are indented even further, namely with the display of "manual.pdf" files. You would now select THEIR parent (or whichever) folders, and not the PDF-files themselves! When you try to copy the selected folders to the destination lister, Dopus lets you choose the copy mode ("rebuild folder structure", "flatten out folder structure" (and overwriting files with same name), ..).

This strategy works perfectly fine (and you cant do this with other file managers!!) but.. with thousands of folders (whose subfolders contain manual.pdf) it is still much work to scroll down the list and select the appropriate folders. i mean, manually selecting 1000 folders is a problem!

so if someone else has a better strategy (with dopus, batch file, regex, etc.)... shoot it.

Ville - how are you/will you decide the new folder names? In your example, you'll want folders

c:\mydir\two
c:\mydir\four\

to each be moved. Are they both going to one new folder, as in:

c:\mydir\two\ --> c:\mydir\NEW\
c:\mydir\four\ --> c:\mydir\NEW\

such that you have:

c:\mydir\two\ --> c:\mydir\NEW\two
c:\mydir\four\ --> c:\mydir\NEW\four\

Or does each go into a different folder, as in:

c:\mydir\two\ --> c:\mydir\NEW_2\
c:\mydir\four\ --> c:\mydir\NEW_4\

MrC, they would both go into a new directory, as in

c:\mydir\two\ --> c:\mydir\NEW\two
c:\mydir\four\ --> c:\mydir\NEW\four\

For that reason I was looking a way to possibly identify/select such folders so that they could be dragged/moved into the 'NEW' folder.

I don't have a vbscript or one that Opus readily uses for you.

If the problem is as you'd describe it, I'd solve it a different way. In my opinion, there are better tools for this job. If you need to physically select files with the mouse, you'll have to write a script.

I would do it like this (the end product):

for i in $(find . -name '*.pdf' | sed 's-^\./\([^/][^/]*\)/.*$-\1-'); do echo mv $i NEW/$i; done

I'm doing using the Cygwin environment, which is a collection of the standard GNU, etc. tools that come on modern *nix platforms. I do it this way because the problem for me is easily broken down into simple parts, which are described as:

  1. get a list of all directories under a tree that have .pdf files
  2. modify that list to consist of the containing directories under the highest level parent directory
  3. move each of those directories into the NEW directory

This can be done other ways (even from within Opus using in perl script, vbscript, etc.), but I find this more cumbersome because testing each step is cumbersome. By using a command shell environment, each piece can be built upon the other, and tested very quickly. It took less than 1 minute to write and test the above. And to me the rapid testing/validation is the important part.

In case you are interested, the above parts are:

  1. Find all pdf files, printing out their relative paths:

$ find . -name '*.pdf' ./five/manual.pdf ./four/subdir/manual.pdf ./one/manual.pdf ./two/manual.pdf

  1. Take that output and strip out stuff below highest level directory below parent

$ ... | sed 's-^\./\([^/][^/]*\)/.*$-\1-' five four one two

  1. Wrap this output now into a loop, and iterate over each resulting directory

$ for i in $(find . -name '*.pdf' | sed 's-^\./\([^/][^/]*\)/.*$-\1-'); do echo mv $i NEW/$i; done mv five NEW/five mv four NEW/four mv one NEW/one mv two NEW/two

Above I just printed out (w/echo) what would be done, so we can see that the correct directories would be moved. One directory (./three) has no pdf, so it is skipped, and directory four contains a subdir where the pdf is located.

If this is useful to you, respond and I'll continue help, or it can be translated into another scripting language.

It is not my intention here to imply that my way is better, or that there is any fault in Opus, an awesome tool.

I ended up creating a TakeCommand batch file (below; a PowerShell batch file would surely work, too, but I'm not very familiar with it). This does the job without having to run Cygwin; Unix shell scripting is great.. on Unix/Linux, but I've always thought Cygwin is bit of a kludge.

@echo off
SETLOCAL
set targetdir=_COLLECTED_DOCS
echo %targetdir%
DO I in (.) /A:D *
 iff isdir %[I] .and. %[I] NEQ %targetdir% then
    pushd %[I]
    set moveflag=false
    DO F in /S *
       iff isfile %[F] then
          iff "%@ext[%F]" eq "pdf" then
             set moveflag=true
          elseiff "%@ext[%F]" eq "epub" then
             set moveflag=true
          elseiff "%@ext[%F]" eq "chm" then
             set moveflag=true
          endiff 
       endiff
    ENDDO
    popd
    iff "%moveflag%" EQ "true" then
       echo Moving dir "%[I]"
       move /S /MD "%[I]" "%targetdir%\%[I]\"
    endiff
 endiff
ENDDO
ENDLOCAL