Muthukumar
Muthukumar

Reputation: 9579

Search a file in a directory using MS DOS

How can I search a directory and its sub directories for a file and display the file name and its created time in a neat format.

I tried dir sam.csv /b /s /a-d

But does't work.

The output should look like

c:\Data\Sam.txt 10/10/2012 10.00 AM

c:\Data\1\Sam.txt 11/10/2012 10.00 AM

c:\Data\2\Sam.txt 12/10/2012 10.00 AM

Or can I do the same in a for loop?

Upvotes: 4

Views: 8107

Answers (3)

Preet Sangha
Preet Sangha

Reputation: 65516

Try this:

for /f %f in ('dir sam.txt /s/b') do @echo %f  %~tf

This is it running.

C:\data>for /f %f in ('dir sam.txt /s/b') do @echo %f  %~tf
C:\data\Sam.txt  26/10/2012 10:49 a.m.
C:\data\1\Sam.txt  26/10/2012 10:49 a.m.
C:\data\2\Sam.txt  26/10/2012 10:49 a.m.

You can get more help on the FOR command using help for at the command prompt

Upvotes: 6

Emo Mosley
Emo Mosley

Reputation: 535

The /b option is stripping out the date information. You can get some great DOS syntax help here:

http://www.computerhope.com/msdos.htm

Upvotes: 1

Reflective
Reflective

Reputation: 3917

dir sam.csv /s /4 shows what you asked in the question. If there is something else, please add it to your question.

Upvotes: 1

Related Questions