How to? Find a specific file in subfolders

Oct 18, 2009
363
17
The folder setup I have is this:

\THR
\THR\Downloads\2017\06 Jun 2017\01 {current month}
\02
\03
etc.
\THR\Downloads\2017\06 Jul 2017\01 {future month}
\02
\03
etc.

A file zcs_20170603.txt is moved to the appropriate day folder.
It might be automatically copied to \THR, depending on a variety of factors.

If not, it has to be manually copied to \THR.

The main program then renames the copy, which ultimately gets deleted.

What I would like to do is have the main program look for the original without using a detailed "walk the tree" program so if the user moves the file rather than copying it the main program won't proceed.

It seems there should be an easy way to do that with ffind /s /f {something} >NUL basically saying "Look in subfolders of \Downloads\ until you find or don't find %source_file." I tried \Downloads\*\ but that doesn't work.
 

samintz

Scott Mintz
May 20, 2008
1,555
26
Solon, OH, USA
If you use Everything Search it happens *really* fast.
Code:
Everything %source_file

If there's only 1 file you could do something like:
Code:
do f in /p everything %source_file (echo File %f was moved! & quit)
 
Oct 18, 2009
363
17
Everything won't work. Both the target file and the .btm file are on network drives.

Also, there will be a copy of the zcs in the folder that contains the .btm, so the search can't include %_cwd. (I didn't realize until after I'd done quite a bit of coding that all data files should have been put folders different from the code folders.)

Speed isn't a major concern. Although \Downloads\ can have 800 subfolders, it would rarely have more than 40 files, and most of those would have a .bak extension, and the target file would be near the top of the tree.
 
May 20, 2008
12,171
133
Syracuse, NY, USA
I don't know about your syntax for FFIND. FFIND works here, used in various ways on a network drive.
upload_2017-6-23_15-28-6.png
 
Oct 18, 2009
363
17
I'm assuming ffind can work with the proper syntax but I haven't been able to figure it out.

The ffind examples aren't relevant. The last one says "search for wdump.btm in a specific folder". The other ones say "search for wdump.btm in the current folder and any subfolders.

I need "search subfolders of a different folder."

The problem in my case is that ffind /s \Downloads\*\zcs_x.txt seems to only search all folders one level below \Downloads.
On the other hand, ffind /s \Downloads{space}\zcs_x.txt searches for \Downloads
 
Oct 18, 2009
363
17
I just checked the syntax for ffind /s and it says

Display matches from the current directory and all of its subdirectories. By default, FFIND processes only those subdirectories without the Hidden or System attributes. To view hidden or system subdirectories use /A along with /S.

If you specify a number following the /S, FFIND will limit the subdirectory recursion to the number specified. For example, if you have a directory tree "\a\b\c\d\e", /S2 will only go to the "a", "b", and "c" directories.

If you specify a + followed by a number after the /S, FFIND will not search for files until it gets to that depth in the subdirectory tree. For example, if you have a directory tree \a\b\c\d\e, /S+2 will not find anything in \a or \a\b.

It looks like it will be necessary to write a subroutine that switches to \Downloads, runs ffind /s+2, and switches back to \THR.


I'm going to put a suggestion to add to ffind the ability to set a full path with subfolders.
 
Oct 18, 2009
363
17
The examples using /a:d find folders and they are looking at subfolders of the current working directory. What I would be trying to do is from a command line in C:\dell search for ABC.txt somewhere in a subfolder of D:\MyFiles\2017\

The Help indicates /s with ffind can only search subfolders of the current folder.

Incidentally, I tried using dir instead and it turns out dir works the same way.

As I mentioned, it looks like I'll have to write a routine that switches to \Downloads, runs ffind and then returns to the original directory. The program I use assigns the original directory path to a variable, so that's not a big deal.
 
May 20, 2008
12,171
133
Syracuse, NY, USA
If you give it a path, that's where it starts looking, not in the CWD.
What I would be trying to do is from a command line in C:\dell search for ABC.txt somewhere in a subfolder of D:\MyFiles\2017\
This seems to be what you mean.
upload_2017-6-24_19-1-38.png

And note: G:\uty\ (and below) is the only place it looked.
 
Oct 18, 2009
363
17
I tried a variation and it worked!

In \THR

[F:\CLIENT DOWNLOADS\THR] ffind /f /s "F:\CLIENT DOWNLOADS\THR\Downloads\zcs_20170622.txt"

F:\CLIENT DOWNLOADS\THR\Downloads\2017\06 - Jun 2017\24\zcs_20170622.txt

[F:\CLIENT DOWNLOADS\THR] ffind /f /s "F:\CLIENT DOWNLOADS\THR\Downloads\zcs_20170623.txt"
0 files

I'll put a follow-up in the Suggestions thread to mention this in the Help.
 

Similar threads