Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

to find files in dos

Posted on 2008-10-05
4
Medium Priority
?
819 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 400 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:
Farhan Kazi earned 800 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 800 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

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…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

885 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