0
votes

H,

I need to create a script to run as a pre-script on our Backup schedule to first move files to a destination folder and delete files older than x days on that dessication folder.

I know I can use Robocopy and forfiles to create separate tasks but i need to run it on the same script..

eg:-

move files in c:\Backup\ to D:\Old_Backup and search for files older than 3 days on D:\Old_Backup and delete them from D:\Old_Backup folder.

Thanks in advance...

1
I don't get it. Why can't you use a robocopy to copy the files and a for loop with remove-item command foreach old files in the same script?Ouarzy
I'm new to scripting.. i just managed to do it by following test script i tested with. robocopy "d:\source" "d:\Delete" /mov forfiles /p "d:\Delete" /m *.inf /D -365 /c "cmd /c del @path" It would be great if you can let me know another way so I can improve my self...Tharaka Perera
The two commands should work fine when on separate lines - just don't call the batch file robocopy or forfiles because it won't work as it should.foxidrive

1 Answers

0
votes

I'd be happy to help you to improve, I just do not understand your question.

If you want to write script for Windows I encourage you to learn how to use PowerShell.

As you describe it, I do not see any reason why you cannot writes it in a single script. Thus my supposition is that maybe it is not clear for you what a script exactly is.

You can write several commands line in your script, thus it should be easy to write a script moving required files and deleting other required files in the same script.

Edit: you will find all required ressources here.