1

I am new to scripting. I want to move some folders (including all files and subdirectories) to another directory based on last modified date of the folder. Something like MAXAGE but for folders and without checking subdirectories

This is what i get now, but it seems not to work.

ForFiles /P "y:\Backup\FullBU" /D +7 /C "CMD /C if @ISDIR==TRUE Move y:\Archive"

Can someone tell me to what I am missing?

androle
  • 33
  • 3
  • you need to tell it what to move such as MOVE _@path or @file_ y:\Archive. – Compo Nov 16 '16 at 14:56
  • 2
    Possible duplicate of [FORFILES date -after- (date calc in cmd file)](http://stackoverflow.com/questions/19296588/forfiles-date-after-date-calc-in-cmd-file) – aschipfl Nov 16 '16 at 15:18
  • I tried with path and file, altough there are files and folders with the criteria of younger then 7 days, there is an error which says "No Files found with the specified search criteria." Any idea? – androle Nov 16 '16 at 15:22
  • @androle, `forfiles` regards the *modification* date only, but *not* the creation date; is the issue you are facing connected to that? By the way, `move` expects *two* arguments -- refer to the help that appears when typing `move /?` into command prompt... – aschipfl Nov 17 '16 at 00:48
  • @aschipfl No, **modification** date works good for me. The issue that im facing to is that i cant move folders with criteria of younger then 7 days (modification date) on just one folder level. Per example I have **C:\Folder1\sub** , im not interested what date the files and subfolders in Folder1 have, i just want to move folders with the criteria on the highest level of the path. With `move` command i have to specify the exact source. Any suggestions? – androle Nov 17 '16 at 09:16
  • So `sub` is the folder to be moved, right? just check out [my answer](http://stackoverflow.com/a/36585535) to the aforementioned duplicate; of course you have to replace the `echo` command line `> con echo @fdate @file` by `move @path 0x22D:\path\to\target\folder\0x22`... – aschipfl Nov 17 '16 at 12:51
  • No, per example we have 5 folders in C:\. I want to move those folders with a maximum age of 7 days based on modified date. Not interested if file inside those folders are older. Sorry i dont understand your code in your other answer. I took my code from this, where you answered before http://stackoverflow.com/questions/39520013/batch-to-move-folders-that-are-30-days-old-using-forfiles but that seems not to work. Maybe a solution with `for` and `robocopy` ? – androle Nov 17 '16 at 13:03
  • @aschipfl I tried your option. The issue now is that it is based on date of files.. – androle Nov 17 '16 at 14:41
  • @aschipfl Exactly like this (your answer) http://stackoverflow.com/a/33556265/7046930 but based on folders without moving files from directories that are older then 7 days – androle Nov 17 '16 at 15:06

1 Answers1

0

What about this:

> nul forfiles /D -0 /C "cmd /C if @isdir==TRUE 2> nul forfiles /M @file /D -8 || > nul move @fdate 0x22Y:\Archive0x22"
aschipfl
  • 33,626
  • 12
  • 54
  • 99