Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

What is the easiest way to search for files from a command line on Windows XP?

I want to look for files created since a certain date, bigger than a certain size, or on a certain drive.

Ideally I would like to be able to save the command with parameters in a text file that I can re-run on a regular basis.

share|improve this question

3 Answers 3

up vote 4 down vote accepted

This can be done with the built-in tools from command-prompt, although you will end up with scripts rather than simple commands. For an easy command-line approach for finding files that meet certain criteria, I'd install PowerShell.

Here are some examples to give you an idea:

to find files created since a certain date in the current directory:

C:\>Get-ChildItem | Where-Object{$_.CreationTime -gt "28/12/2009 8:00:00 PM"}


    Directory: Microsoft.PowerShell.Core\FileSystem::C:\


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        28/12/2009   3:56 PM          0 newfile.txt

to find a text file bigger than a certain size in the current directory (in bytes):

C:\> Get-ChildItem | Where-Object{$_.length -gt 16000}


    Directory: Microsoft.PowerShell.Core\FileSystem::C:\


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        21/12/2009   7:02 PM      16504 svc.txt

to find all mp3 files on a different drive:

C:\> Get-ChildItem D:\ -include *.mp3 -Recurse -Force


    Directory: Microsoft.PowerShell.Core\FileSystem::D:\


Mode                LastWriteTime     Length Name
----                -------------     ------ ----

-a---        12/03/2009   4:01 PM    4418246 eric clapton - tears in heaven.mp3
-a---        22/05/2009   2:24 AM    7714143 led zeppelin - stairway to heaven.mp3
-a---        13/06/2009   2:39 AM    5507148 pearl jam - black.mp3
-a---        13/06/2009   2:39 AM    3042452 pearl jam - last kiss.mp3
-a---        31/12/2008   5:43 AM    3216613 rush - fly by night.mp3
-a---        31/12/2008   6:37 AM    4267363 Rush - Limelight.mp3
-a---        31/12/2008   6:02 AM    4224300 rush - yyz.mp3
-a---        07/12/2008   2:05 AM    2827218 rush - closer to the heart.mp3
-a---        19/05/2009   5:21 AM    5842779 styx - come sail away.mp3


Out of curiosity though, why can't Windows Search be used? It can do everything you require easily with a GUI.

share|improve this answer

Well, if we're mentioning non-default scripting languages, I use the freeware TCC/LE. All of the commands support date/size ranges.

I want to look for files created since a certain date, bigger than a certain size, or on a certain drive.

To look for all files within the 7 days:

dir /sf /[d-7]

To look for all files since October 30th of 2009:

dir /sf /[d2009-10-30]

To look for files larger than 57,000 bytes:

dir /sf /[s57000]

To look for files smaller than 57,000 bytes:

dir /sf /[s0,57000]

As for saving the command in a text file, you can set up aliases to do the same thing, ie.

alias today=dir /sf /[d0]
alias week=dir /sf /[d-7]
share|improve this answer

Personal preference is to just get a copy of the unix find command ported to windows. 65k EXE file and in about the last 20 years I haven't come across anything it can't find based on the various switches and options. Then add the option to act on any file it finds, very useful. Too many examples to list here but check out

http://linux.about.com/od/commands/l/blcmdl1_find.htm
and
http://content.hccfl.edu/pollock/unix/findcmd.htm

It can be found in the zip file found at http://sourceforge.net/projects/unxutils/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.