Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search a file in a directory using MS DOS

Tags:

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?

like image 793
Muthukumar Avatar asked Oct 15 '25 14:10

Muthukumar


1 Answers

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

like image 73
Preet Sangha Avatar answered Oct 18 '25 09:10

Preet Sangha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!