Solved

to find files in dos

Posted on 2008-10-05
4
812 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

751 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