Batch script command

77 views Asked by At

I am a rookie at programming. I have created a batch script to move files from one location to other based on date. I want to move all files expect the files having modification date 3 days lesser than the current date.Also I want to log the files which has been moved in a new text document. I am able to move the files but not able to log the moved files. Command which i used is

forfiles /p C:\Users\Desktop\batchtest\ /s /m . /d -3 /c "cmd /c move @FILE \"C:\Users\Desktop\nov""

What i need is to create a textfile which shows the files moved by the above command.Could someone help me on this? This is not same to Just deleting the file based on the date I suppose.

1

There are 1 answers

5
gusg21 On

You could redirect all command output in to a file, like so: forfiles /p C:\Users\\Desktop\batchtest\ /s /m . /d -3 /c "cmd /c move @FILE \"C:\Users\Desktop\nov"">log.txt

Notice the ">log.txt". That will redirect all non-error output into the provided file. It will create it if it isn't there. If you want to redirect errors, too, put a 2>log.txt >log.txt at the end instead. Source