Dir multiple folder search

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
iulian.fartade
Posts: 2
Joined: 13 Aug 2018 03:39

Dir multiple folder search

#1 Post by iulian.fartade » 13 Aug 2018 04:00

Good day!

I am having some issues with the basics, I'm sorry to use your time but I had spent several days of search and got no results.

I have the next folder structure, in a test folder on the desktop:

Code: Select all

\test
       \1
           \empty
       \2
           \a11.txt
           \b11.txt
       \3
           \a11.txt
           \b11.txt
       \a1
           \empty
       \a2
           \a11.txt
           \b11.txt
       \a3
           \empty
       \Test1
           \a12.txt
           \b12.txt
       \Test2
           \a23.txt
           \b23.txt
What I need to do is create a list, containing (if exists) the existence of a .txt file starrting with "a" and the folder that contains it. This batch will need to give only the result of the \TestX folders.
The code I tried is simple:

DIR C:\Users\Tesla-Project\Desktop\test\a*.txt /S /O -L >lista.txt 2>&1
START lista.txt

The issue with this code is that it runs all folders contained in \test folder. If this folder contains a lot of files the batch will take a very long time to process.
I need to exclude the 1,2,3,a1,a2,a3 folders and have the program run only \Test1 and \Test2 folders.
If I try to use % or * for the Test folder, I have no result:

DIR C:\Users\Tesla-Project\Desktop\test\Test*\a*.txt /S /O -L >lista.txt 2>&1
START lista.txt

I feel like I am missing something very simple but I really cannot find a solution for this...
Could someone help me on this please?
Last edited by aGerman on 13 Aug 2018 08:28, edited 1 time in total.
Reason: code tags added to preserve indentations

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Dir multiple folder search

#2 Post by aGerman » 13 Aug 2018 08:53

You can target a list of folders in just one DIR command line.

Code: Select all

DIR "C:\Users\Tesla-Project\Desktop\test\Test1\a*.txt" "C:\Users\Tesla-Project\Desktop\test\Test2\a*.txt" /A:-D /S /O /L
Steffen

iulian.fartade
Posts: 2
Joined: 13 Aug 2018 03:39

Re: Dir multiple folder search

#3 Post by iulian.fartade » 13 Aug 2018 11:09

aGerman wrote:
13 Aug 2018 08:53
You can target a list of folders in just one DIR command line.

Code: Select all

DIR "C:\Users\Tesla-Project\Desktop\test\Test1\a*.txt" "C:\Users\Tesla-Project\Desktop\test\Test2\a*.txt" /A:-D /S /O /L
Steffen
Thank you Verry Much Steffen!!!

Do you think it would also be possible to filter the result and save in the list only the files created 1 day ago?
I tried to do this using:
forfiles /m "a*.txt" /d -1
The /m thow is not recognized... If I remove the /m I have a result but it seems to completely ignore the mentioned line.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Dir multiple folder search

#4 Post by aGerman » 13 Aug 2018 13:22

You may use FORFILES instead of DIR but you'll lose the ability of searching in several folders at once. Also /D -1 means that the files are at least one day old (not exactly one).

Code: Select all

forfiles /p "C:\Users\Tesla-Project\Desktop\test\Test1" /m "a*.txt" /d -1 /s /c "cmd /c echo @path"
Steffen

Post Reply