Windows file search question

I have a conundrum here at work. I have a series of subfolders that are named by year and month. i.e. 200602; 200603 … 200902 where we put files that related to that particular year month combo.

I’m looking for a way to find a file, but I only want to look in the folders 200801 to 200902. I know part of the file name so I can pattern matching. Is there any way to limit a search to some directories in hierarchy but not all of them?

From my perspective I only have two choices, searching once for each directory I want to look in, or search ALL of the directories of the same hierarchy with the ‘search subfolders’ option turned on.

I’m not against using command line, but I don’t see any switches in the dir command that allows me to do something like dir 2008**fileA.txt

This is obviously a windows based machine.

Try something along the lines of



For %f in (6 7 8 9) do for %g in (01 02 03 04 05 06 07 08 09 11 12) do dir 200%f%g\*fileA.txt


Quartz’s idea will do everything from 200601 to 200912. That’s not quite what you asked for, but is certainly on the right track.

There’s not a super-easy way to do just the ones 200801 to 200902. But that’s only 13 entries, so we can stand to just enumerate them in code.



c:>for %d in (200801 200802 200803 200804 200805 200806 200807 200808 200809 200810 200811 200812 200901 200902) do dir %d\{file name pattern goes here}


will do your job for you.

If you needed, say, 30 contiguous months out of a period of 10 years, we could add some more algorithmic stuff, but for 13, that’s be worse than this is.

Create a new temp folder, move those 13 subfolders into it, and then search it. When you’re done, move those folders back from that temp folder to their original spots.

That is exactly what I was going to say.

How about

for /f “usebackq” %d in (dir /b 2008*) do dir %d*fileA.txt

Note the backquotes inside the parentheses. That makes Windows run the command and use each line of the output in the for loop.

Actually, I think you can use regular single quotes, so it’s just:

for /f %d in (‘dir /b 2008*’) do dir %d*fileA.txt

The usebackq thing is only if you want to use single quotes for strings.

But the OP wanted all 2008s, and two 2009s.

The OP said

That’s exactly what mine and other suggestions do. Obviously you can change the 8 to a 9.
I got the impression that the OP limited it to 200902 simply because there is no 200903 directory yet.

To me, it looks like you have 14 specific folders you want to look in. I would copy those folders to a new temporary folder, and then just search that entire folder.

No fuss, no muss, no programming.

Ref posts 4 & 5. :slight_smile:

:smack: how did i miss those? :smack:
thanx!

Hmm I suppose copying the files would work; although that seems more work than just using the for command.

On a side note; I always forget about the ‘for’ command and how useful that is.

This is true, I just wanted to look in the last 16-18 months of folders.