0

I need to generate a Windows batch file that detects .zip files older than a certain amount of hours (12) and then moves them to another folder. I'd really like to use a batch file, but I do know Java and if this could be more easily archived in a jar, I can try that as well.

An alternate option I'd like to see is how to generate a list of those old .zip files written to a text file.

Btw, deleting the files won't help me. I know there are similar questions but I'm not familiar enough with the syntax to combine the different answers I've seen. Any suggestions would be appreciated.

Naomi
  • 11
  • 1
    Please note that SO is not a code writing service; so you should share what you've tried so far and describe where you're stuck by editing your post... – aschipfl Sep 16 '15 at 22:19
  • `File#lastModified` compared to some `Date` value which represents the threshold time your looking for and `Files.copy` could do it – MadProgrammer Sep 16 '15 at 22:19
  • What did you do so far? – CristiFati Sep 16 '15 at 22:36
  • Pure code-writing requests are off-topic on Stack Overflow -- we expect questions here to relate to *specific* programming problems -- but we will happily help you write it yourself! Tell us [what you've tried](http://whathaveyoutried.com), and where you are stuck. This will also help us answer your question better. – Elliott Frisch Sep 16 '15 at 22:46
  • @Naomi `robocopy` can do that, you can start in cmd with `robocopy /?` Edit: just checked and it can do with `n` days, `1` are the minimum – Paul Sep 16 '15 at 23:59
  • @Naomi, `robocopy *.txt /maxage:1 /L` (remove `/L` for apply) also `forfiles` support 0 days `forfiles /D 0 /m "*.txt" /c "cmd /c echo @file @fdate @ftime"` then you have to make arithmetic operation to convert time in minutes and compare with the current time. I agree that is not easy because there can be issue if you run the script at some time of the day. – Paul Sep 17 '15 at 01:14
  • @Paul: Excuse me, but suggest a method and then add "but this not works" is worst than post nothing at all. What is the usefulness of your last two comments? – Aacini Sep 17 '15 at 01:41
  • @Aacini Excuse me too but, I suggested just a direction where to look. I even during that time too look how to compare the file date with the date of the moment. And I realized that it was not easy. I try to help him because I think the question is interesting. Now the real question I ask you: Is that my comment is less useful than a comment like "SO is not a code writing service" ? – Paul Sep 17 '15 at 01:52
  • @Aacini Also my ideas, specifically with `forfiles` and converting `@fdate` `@ftime` into a unix like time-stamp are not bad. I just didn't figured out how to do that in windows. – Paul Sep 17 '15 at 01:59
  • @Naomi, look on answer [Batch file to delete files older than N days](http://stackoverflow.com/a/28395552/3074564) and adapt the batch code to your slightly different requirements which means moving file instead of deleting it, -12*3600 seconds instead of -7 days (variable `LastWeek` which should be also renamed) and of course make sure that date and time string passed to `GetSeconds` is in one of supported formats or adapt `GetSeconds` routine to date and time string format used on your machine. – Mofi Sep 17 '15 at 06:03
  • You could use [this JScript FSO solution](http://stackoverflow.com/a/27297874/1683264) and move files gtr 7200 minutes old. Also remove the `%1` stuff and use a `for` loop like `for %%x in (*.zip)` – rojo Sep 17 '15 at 13:05
  • @Paul: Well, I could suggest: "Use `%date%` and `%time%` variables to get current time and compare it vs file's created time, or use `wmic` command for the same purpose, or use a Batch-JScript hybrid script to do the math, or use my [StdTime.exe auxiliary program](http://www.dostips.com/forum/viewtopic.php?f=3&t=3428&p=17610#p17610) (that includes a "List files modified in the last 3 hours" example) to do the same, etc..". However, this would not help the OP to solve the problem, just give more "directions where to look". IMHO the `forfiles` method should be presented as a working solution... – Aacini Sep 17 '15 at 18:40
  • possible duplicate of [Find out if file is older than 4 hours in Batch file](http://stackoverflow.com/questions/6928552/find-out-if-file-is-older-than-4-hours-in-batch-file) – Mofi Sep 21 '15 at 05:33

0 Answers0