We needed a solution for a shared folder that we wanted to control so that users didn't use it as a lazy dumping ground for their files.
After a bit of searching I found a novel way of using robocopy to accomplish exactly what we wanted.
mkdir c:\delete
c:\robocopy.exe c:\Source c:\Delete /e /MOVE /MINAGE:14 /LOG+:c:\robocopy.log
rmdir c:\delete /s /q
This script creates a folder called 'delete'. Then uses robocopy to move files older than 14 days from the 'source' folder to the 'delete' folder. Lastly it deletes the 'delete' folder so that only files newer than 14 days is left in the 'source' folder.
Notes:
Remember to change the location of the robocopy executable, robocopy.log, your source and delete folders.
Add '/XF [filename]' to the robocopy line in order to exclude one or more files from being deleted (if required).
Original article can be found here. (Pure genius!)
47 comments:
To erase one complex dir i use the command:
robocopy e:\empty e:\to_delete /MIR /E
e:\empty is a empty dir. its fast :-)
Is there a way i can edit this script to copy files to a new locaiton versus deleting?
' Objective: To delete old files from a given folder and all subfolders below
'
' Created by: ANT Mar 28, 2012
'
' Format: cscript deloldfiles.vbs {DriveLetter:\FolderName} {#ofDays}
' or: cscript deloldfiles.vbs {\\servername\FolderName} {#ofDays}
' Example: cscript deloldfiles.vbs c:\dba\log 3
' (deletes files older than 3 days from the \dba\log file on drive C:)
Set objArgs = WScript.Arguments
FolderName =objArgs(0)
Days=objArgs(1)
set fso = createobject("scripting.filesystemobject")
set folders = fso.getfolder(FolderName)
datetoday = now()
newdate = dateadd("d", Days*-10, datetoday)
wscript.echo "Today:" & now()
wscript.echo "Started deleting files older than :" & newdate
wscript.echo "________________________________________________"
wscript.echo ""
recurse folders
wscript.echo ""
wscript.echo "Completed deleting files older than :" & newdate
wscript.echo "________________________________________________"
sub recurse( byref folders)
set subfolders = folders.subfolders
set files = folders.files
wscript.echo ""
wscript.echo "Deleting Files under the Folder:" & folders.path
wscript.echo "__________________________________________________________________________"
for each file in files
if file.datelastmodified < newdate then
wscript.echo "Deleting " & folders.path & "\" & file.name & " last modified: " & file.datelastmodified
on error resume next
' === to test this script but not actually delete files, comment out the next line ===
file.delete
end if
next
for each folder in subfolders
recurse folder
next
set subfolders = nothing
set files = nothing
end sub
In order to keep the moved files and not delete them you can simply ommit the last line of the script.
mkdir c:\delete
c:\robocopy.exe c:\Source c:\Delete /e /MOVE /MINAGE:14 /LOG+:c:\robocopy.log
and not do
rmdir c:\delete /s /q
To speed things up you can use the /CREATE option which will create zero-length files.
Brilliant! That's exactly what I need, thanks. And adding the /CREATE option is a clever touch :)
Nice post.Another software alternative that works is "LongPathTool" for error messages: Cannot read from source file or disk, there has been a sharing violation, cannot delete file or folder, the file name you specified is not valid or too long, the source or destination file may be in use and many other file managing errors.
GSCopy Pro v6.0 (RoboCopy Alternative) with Open File Agent
GSCopyPro is a single command-line tool (CLI) that can copy, replicate and move files from one folder to another. This folder can be on the same machine/ server or another server elsewhere. What makes GSCopyPro stand out from other competitors is the fact it works on 32-bit as well as 64-bit systems and has no restrictions. It can easily be scheduled to run as a scheduled task and fully automated. GSCopyPro also comes with an open file agent which can copy files that are locked/ opened by other processes. This feature is supported in all windows versions from widows XP/ 2003 and later.
Go To:>> http://www.gurusquad.com/GSCOPYPRO
To delete all files older than 14 days in folder C:\Source, the command below works in Microsoft Windows Version 6.3.9600 (and other versions). Good help and examples by running FORFILES /?
FORFILES /P C:\Source /D -14 /C "cmd /c Del @file"
All,
I created below script based on this tech note. I am trying delete files which are unused more than 10 days.. But it is not working..Can you please take a look and suggest what is wrong...
mkdir c:\delete
c:\robocopy.exe c:\Source c:\Delete /e /XF/C:\Source\Project /MOVE /MAXLAD:10 /LOG+:c:\robocopy.log
rmdir c:\delete /s /q
c:\robocopy.exe c:\Source c:\Delete /e /XF/C:\Source\Project /MOVE /MAXLAD:10 /LOG+:c:\robocopy.log
change maxlad to maxage...
I like your thoughts due to your skills.
hello, your website is really good. We do appreciate your give good results toptenreviews.com
use robocopy
After a bit of searching I found a novel way of using robocopy to accomplish exactly what we wanted.
mkdir c:\delete
c:\robocopy.exe c:\Source c:\Delete /e /MOVE /MINAGE:14 /LOG+:c:\robocopy.log
rmdir c:\delete /s /q
This script creates a folder called 'delete'. Then uses robocopy to move files older than 14 days from the 'source' folder to the 'delete' folder. Lastly it deletes the 'delete' folder so that only files newer than 14 days is left in the 'source' folder...but in my opinion some other tools are better then robocopy...currently i am using GS Richcopy 360 for these type of work.
Is there a way to use robocopy to move a folder that is named after the machine name and then date/time stamped to another folder? Folder currently look like this:
ABC-TEMP-001_20180409-1201
I tried %COMPUTERNAME%_%datetimestamp%, but that end ups looking for the foldername with the current date/time stamp.
"""After a bit of searching I found a novel way of using robocopy to accomplish exactly what we wanted.
mkdir c:\delete
c:\robocopy.exe c:\Source c:\Delete /e /MOVE /MINAGE:14 /LOG+:c:\robocopy.log
rmdir c:\delete /s /q
This script creates a folder called 'delete'. Then uses robocopy to move files older than 14 days from the 'source' folder to the 'delete' folder. Lastly it deletes the 'delete' folder so that only files newer than 14 days is left in the 'source' folder..,however in my opinion there are other tools are which are way better then robocopy.Currently i am using GS Richcopy 360 for these type of work.
Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.
rpa Training in Bangalore
Lovely Article. Very Helpful story. Please keep posting.
RPA Training in Hyderabad
RPA Training in Chennai
RPA Training in Bangalore
Cool! it works like a champ!
UiPath Training in Bangalore by myTectra is one the best UiPath Training. myTectra is the market leader in providing Robotic Process Automation on UiPath
robotic process automation training in bangalore
I get a lot of great information from this blog. Recently I did oracle certification course at a leading academy. If anyone interested to learn best Oracle Course in Hyderabad visit Go Trainings Academy which offer SQL Training in Hyderabad.
Best Training and Real Time Support
Oracle Bpm Training
Oracle Osb Training
Come to BGAOC and play great games. good blackjack game Here you can play online casinos and earn large sums of money.
The information given is extra-ordinary. Looking forward to read more . Thanks for sharing.
IELTS Coaching in Chennai
IELTS Training in Chennai
IELTS classes in Chennai
IELTS Training in Tambaram
Spoken English Classes in Chennai
Best Spoken English Classes in Chennai
SAS Training in Chennai
SAS Course in Chennai
На любой вкус светодиодные ленты можно найти в Ekodio, бюджетные и премиум, всех цветов и характеристик
Hi, I met one gambling site, new play online gambling real money it was very cool, it was fun and spent some time with the conclusion that there were no problems the very best site cool design, a bunch of slots and slot machines
Thanks for posting this info, I found it very interesting and informative.
RPA Training in Chennai
Robotics Process Automation Training in Chennai
Blue Prism Training in Chennai
UiPath Training in Chennai
Data Science Course in Chennai
RPA Training in Anna Nagar
RPA Training in Chennai
RPA course in Chennai
Excellent Post. Extra-ordinary work to share with. Thanks for posting.
Node JS Training in Chennai
Node JS Course in Chennai
Node JS Training Institutes in chennai
Node JS Course
Node JS Training in Anna Nagar
Node JS Training in Porur
Node JS Training in Adyar
Hi,
Best article, very useful and well explanation. Your post is extremely incredible.Good job & thank you very much for the new information, i learned something new. Very well written. It was sooo good to read and usefull to improve knowledge. Who want to learn this information most helpful. One who wanted to learn this technology IT employees will always suggest you take Best Training institutes for python course in BTM Layout
Very useful post,thanks for sharing.Very clear and understandable content.ElasticSearch is a search engine based on Lucene Library
elasticsearch training institute in btm layout
Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
Oracle Training | Online Course | Certification in chennai | Oracle Training | Online Course | Certification in bangalore | Oracle Training | Online Course | Certification in hyderabad | Oracle Training | Online Course | Certification in pune | Oracle Training | Online Course | Certification in coimbatore
Thank you for the informative post. It was thoroughly helpful to me. Keep posting more such articles and enlighten us.
Web Designing Training Course in Chennai | Certification | Online Training Course | Web Designing Training Course in Bangalore | Certification | Online Training Course | Web Designing Training Course in Hyderabad | Certification | Online Training Course | Web Designing Training Course in Coimbatore | Certification | Online Training Course | Web Designing Training Course in Online | Certification | Online Training Course
Thank for this post. I’m really happy to say it was an interesting post to read. I learned new information from your post. you can visit our blog Mom Blog Names
Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.
java training in chennai
java training in omr
aws training in chennai
aws training in omr
python training in chennai
python training in omr
selenium training in chennai
selenium training in omr
I really glad to read your great post and I like your written style. I am waiting for your numerous post...
web designing training in chennai
web designing training in tambaram
digital marketing training in chennai
digital marketing training in tambaram
rpa training in chennai
rpa training in tambaram
tally training in chennai
tally training in tambaram
Thanks for your informative article,Your post helped me to understand the future and career prospects & Keep on updating your blog with such awesome article.
sap training in chennai
sap training in porur
azure training in chennai
azure training in porur
cyber security course in chennai
cyber security course in porur
ethical hacking course in chennai
ethical hacking course in porur
I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously in their life, he/she can earn his living by doing blogging.thank you for thizs article.
java training in chennai
java training in velachery
aws training in chennai
aws training in velachery
python training in chennai
python training in velachery
selenium training in chennai
selenium training in velachery
Excellent Post. Extra-ordinary work to share with. Thanks for posting. Best article to read.
hardware and networking training in chennai
hardware and networking training in annanagar
xamarin training in chennai
xamarin training in annanagar
ios training in chennai
ios training in annanagar
iot training in chennai
iot training in annanagar
Thanks fro the great informative post keep shring!.
acte reviews
acte velachery reviews
acte tambaram reviews
acte anna nagar reviews
acte porur reviews
acte omr reviews
acte chennai reviews
acte student reviews
Good blog, it's really very informative, do more blog under good concepts.
Digital Marketing Course in OMR
Digital Marketing Course in T Nagar
Digital Marketing Course in Anna Nagar
Digital Marketing Course in Velachery
Digital Marketing Course in Tambaram
Thank you much more for sharing the wonderful post. Keep updating here...
Excel Training in Chennai
Excel Advanced course
Pega Training in Chennai
Linux Training in Chennai
Tableau Training in Chennai
Unix Training in Chennai
Oracle Training in Chennai
I genuinely appreciated understanding it. Sitting tight for some more incredible articles like this from you in the nearing days.
Big Data Training Institute in Pune
Hadoop Training in Pune
Wow, it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and I got more information from your blog.
Data Science
Selenium
ETL Testing
AWS
Python Online Classes
That's really impressive and helpful information you have given, very valuable content.
We are also into education and you also can take advantage really awesome job oriented courses
Welcome! Exceptionally supportive counsel inside this article! It is the little changes that produce the biggest changes. Much obliged for sharing!
liveskye
Post a comment