Primary Menu Skip to content. Search for: Search Button. Secondary Menu Skip to content. To totally unlock this section you need to Log-in Login Sometime we need some little simple tool to check and delete files in a specified directory on a system. I use variables because the line can get quite long and I can reuse them for other locations. You just need to find the dos path to your recycle bin associated with your login. This is on a work computer for me and it works.
You might be able to pull this off. You can take a look at this question , for a simpler example. The complexity comes, when you start comparing the dates. It may be easy to tell if the date is greater or not, but there are many situations to consider if you need to actually get the difference between two dates.
Expanding on aku's answer, I see a lot of people asking about UNC paths. Simply mapping the unc path to a drive letter will make forfiles happy.
Mapping and unmapping of drives can be done programmatically in a batch file, for example. This will delete all files with a. If you want to make sure Z: isn't mapped to anything else before using it you could do something simple as. This one did it for me. It works with a date and you can substract the wanted amount in years to go back in time:. The script will allow you to use measurements like days, minutes ,seconds or hours.
To choose weather to filter the files by time of creation, access or modification To list files before or after a certain date or between two dates To choose if to show files or dirs or both To be recursive or not. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Batch file to delete files older than N days Ask Question. Asked 13 years, 4 months ago. Active 10 months ago. Viewed 1. Improve this question. Stephan Kibbee Kibbee Jeff Atwood answered this on Serverfault which I think should be documented here. A new method based in a. EXE commands only has been posted here: stackoverflow. It even allows for a more sophisticated deletion scheme: in addition to keeping files of the last 7 days, it e.
Jan-Philip Gehrcke. Add a comment. Active Oldest Votes. Later versions of Windows and Windows Server have it installed by default. For Windows 7 and newer including Windows 10 : The syntax has changed a little. Improve this answer. FZs Russell: PATH is the full path, including name.
FILE is only the name, so if you're dealing with subfolders, it won't work. This answer works when "older than 7 days" is defined as "modified more than 7 days ago" rather than "created more than 7 days ago". How can the latter be achieved? Show 22 more comments. David Tonhofer Iman Iman 6 6 silver badges 2 2 bronze badges.
For the most part, this is a fairly impractical answer. If I have a directory with lots of data in it, there is will not work well. I'd go with one of the answer that does it "in place" — adamb0mb. As robocopy is really robust, it will in fact work for any directory size, obscure file names, basically arbitrary path lengths and include directories if you need it to - something which surely cannot be said about many other Windows utilities.
Plus, robocopy does support UNC paths - which forfiles from the accepted answer won't do. My thoughts were more along the lines: "My files are already where I want them.
I don't want to have to move them. Don't overload Robocopy to do it" — adamb0mb. Show 2 more comments. Ok was bored a bit and came up with this, which contains my version of a poor man's Linux epoch replacement limited for daily usage no time retention : 7daysclean.
Change : if! I hope this helps. Jay Jay 1, 15 15 silver badges 14 14 bronze badges. Way late and totally unrelated, but 7daysclean. Sathyajith Bhat Arno Jansen Arno Jansen 2 2 silver badges 2 2 bronze badges. HOW TO? Later versions of Windows and Windows Server have it installed by default. For Windows 7 and newer including Windows 10 : The syntax has changed a little. Ok was bored a bit and came up with this, which contains my version of a poor man's Linux epoch replacement limited for daily usage no time retention : 7daysclean.
Change : if! I hope this helps. Top 3 video Explaining windows - Batch file to delete files older than N days. Is there an equivalent of 'which' on the Windows command line? Ignoring directories in Git repositories on Windows. Filename too long in Git for Windows.
0コメント