Solved

to find files in dos

Posted on 2008-10-05
4
808 Views
Last Modified: 2011-09-20
I want to search files in dos by age or last modified time .I want it in a form of a script and not using windows search option in the start menu...For example I want to find all the files that are more than one month old and which are greated than 5 Mb and delete them.. Thanks in advance..
0
Comment
Question by:conversekid
4 Comments
 
LVL 5

Assisted Solution

by:Didier Vally
Didier Vally earned 100 total points
ID: 22647618
Try this link with a lot of useful examples of VBS scripts that will help you :
http://www.scriptinganswers.com/vault/Files%20and%20Folders/
0
 

Author Comment

by:conversekid
ID: 22647732
Thanks but I require in dos scripting ..Thanks
0
 
LVL 26

Accepted Solution

by:
farhankazi earned 200 total points
ID: 22648977
Try following command line statement.
You may need "FORFILES.exe" (comes with Windows 2000 Resource Kit & Vista)

Windows 2000 Resource Kit:
http://www.petri.co.il/download_free_reskit_tools.htm

Following statement will find *.log file in C: drive that modified over 100 days ago and are greater then 5 MB.

Click Start -> Run -> Cmd.exe -> Copy & Paste below statement on command prompt

Hope this helps!
Farhan



FOR /F "tokens=1-2*" %a IN ('FORFILES -pc:\ -m*.log -d-100 -c"Cmd.exe /C @ECHO @FSIZE @FILE"') DO @IF %a GEQ 5242880 @ECHO %b %a

Open in new window

0
 
LVL 31

Assisted Solution

by:Paranormastic
Paranormastic earned 200 total points
ID: 22669754
Another option using robocopy (comes with server 2003):
robocopy %sourcedir% %destdir% %file(s)% /S /ZB /COPYALL /MOVE /MINLAD:31 /V > robocopy_%date:~10,4%_%date:~4,2%_%date:~7,2%.log

this would move files and delete the old ones from sourcedir to destdir - if you do not specify files then all would be included.  includes subfolders, copying in restartable/backup mode (if it cannot be currently accessed), and instead of using last modified date would look at the last accessed date, which might be more desirable.  

You can run with /L to just list what would be done without doing it
You can use /XF to exclude file types that you do not want to move (e.g. /XF *.mp3) - we did this when moving user directories from one file server to another, they were not supposed to have movies, music, etc. stored on their share drive.  This could also be found with dir /s *.mp3 > mp3.log  to list and then go through and delete via batch script easily created from the output ;)

Note that if you run in a mixed environment with non-windows boxes this can be nice as it will not err out if a mac or linux box created a file with a space after the end of the extension or used other normally invalid characters not allowed by a regular copy function.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now