Hi guys,

I am still new on this community and I need your help to build a robocopy script that can be used for do some tasks in one time only. Is it possible?

So, here are the tasks that I want to perform by using robocopy script:

1- Move files older than x days to another folder.
2- Take those files and zip them up. (name zipped file with the date stamp).
3- Delete the files that just got zipped.
4- Move Zipped files to another directory.

Are there any of you guys here know how to do it?please help me and I will appreciating all of your suggestion or ideas. Thanks

7 Spice ups

for robocopy move older than 10 days - chnage as you see to fit

robocopy %source% %destination% /MOV /COPYALL /MAXAGE:10 /R:5 /W:30 /LOG+:log.txt

and here you have entire script to zip files with date stamp and move

http://community.spiceworks.com/scripts/show/835-zip-7zip-files-with-date-and-move-very-simple-and-works

2 Spice ups

Thank you so much for responding my problem, but I still wondering if the scripts could be merged or combined in one file. Is it possible?do you know how to make it?

yes it could be easily merged together as one batch file

2 Spice ups

OK, but how to do that?I never using robocopy script before. so, please tell me in details. thanks

Have you not done a batch file before?

They’re quite simple, just one line after another. They will complete in order, and won’t start until another is finished. (REM = comment)

REM Set locations

SET source = “”

SET destination = “”

SET finallocation = “”

REM Move files older than x days to another folder.

robocopy %source% %destination% /MOV /COPYALL /MAXAGE:10 /R:5 /W:30 /LOG+:log.txt

REM Take those files and zip them up. (name zipped file with the date stamp).

(See link from CloudMan)

REM Delete the files that just got zipped.

DELTREE /Y %desitination%

REM Move Zipped files to another directory.

MOVE /Y %destination% %finallocation%

After you have all this working, you might want to work on logging to help with any errors that may appear…

4 Spice ups

To create a batch file, open Notepad, type the lines of code, then save as *.cmd extension. .bat works as well but is deprecated and some (more complex) functions do not work in .bat files, so it is good practice to always use .cmd unless you really know what you are doing and why.

2 Spice ups

I haven’t had done any kind of robocopy script or any of batch files when working in network area. Usually I just configure some IPs or basic networking stuff. So, its my first time working with batch or cmd scripting. Anyway, thanks guys for all of your suggestion and help. I will testing the code and see if there are any error or problem, then I will let you know. Thanks

Hi,

I have written the script as Smitro has been explained and I got an error. Here I have attached the script file and below is the error that I got recently :


ERROR : No Destination Directory Specified.

Simple Usage :: ROBOCOPY source destination /MIR

source :: Source Directory (drive:\path or \server\share\path).
destination :: Destination Dir (drive:\path or \server\share\path).
/MIR :: Mirror a complete directory tree.

For more usage information run ROBOCOPY /?

**** /MIR can DELETE files as well as copy them !

Is that mean I have misconfigured any path?Please help me identify the error and again so sorry I still newbie in this scripting stuff as I have been so long not work with this kind of thing. Thanks

BackUp_3.rar (513 Bytes)

Hey mate. I just had a very quick looks at your script as I’m on my phone. Please kindly post the code in your repsonse instead of zipping it as it’s hard to access.

I can immediately see ay least part of your problem. You have to put the variable names in the %

For example:
SET source = c:\data
Echo %source%

Apply the same principle to your code and you see how you go

1 Spice up

Yes, I have the same problem, I don’t have anything to open a rar file. If you don’t post it in line, a text file would be good.

1 Spice up

Hi guys,

So sorry for the problem, that’s my bad. I thought you guys always working with pc instead of phone. Okay here I show you the script that I have created recently based on Smitro guidance:

REM Set Destination Login Authentication

net use \10.0.0.219\Test Tsunami247 /user:10.0.0.219\ITTest

REM Set locations

SET source = D:\SafetyLineVoiceMsg

SET destination = \10.0.0.219\Test

SET finallocation = z:\

REM Move files older than x days to another folder.

robocopy %D:\SafetyLineVoiceMsg% %\10.0.0.219\Test% /MOV /COPYALL /MAXAGE:10 /R:5 /W:30 /LOG+:log.txt

REM Take those files and zip them up. (name zipped file with the date stamp).

7z a \10.0.0.219\Test\newFileName%date:~4,2%-%date:~7,2%-%date:~10%.7z @\l10.0.0.219\Test\files_to_backup.txt

REM Delete the files that just got zipped.

DELTREE /Y %\10.0.0.219\Test%

REM Move Zipped files to another directory.

MOVE /Y %\10.0.0.219\Test*.*% %z:%

I named the file “BackUp_3.cmd”, but the script itself not working successfully. What the problem actually with it?

I was tested and ran the script on two machine like the following:

  • Source: D:\SafetyLineVoiceMsg – contains some tested files to be backed up and its stored in windows 8 x64 (physical machine)

  • Destination: \10.0.0.219\Test – this is a network folder that stored in windows 7 ultimate x64 (virtual machine using vitualbox)

Those all some explanation related to my problem and if you need some more detail, let me know and again please guy I very need your help. Thanks

log.txt (23.6 KB)

@James: I have tried your solutions but I still cannot run the script properly and got another new error like could not find any specific destination. See the log file and script that I have been included recently on my previous post. Thanks

just briefly … change this line:

robocopy %D:\SafetyLineVoiceMsg% %\10.0.0.219\Test% /MOV /COPYALL /MAXAGE:10 /R:5 /W:30 /LOG+:log.txt

to

robocopy %source% %destination% /MOV /COPYALL /MAXAGE:10 /R:5 /W:30 /LOG+:log.txt

I already did it,but still not working. Here is my recent update of my script:

REM Set Destination Login Authentication
net use \10.0.0.219\Test Tsunami247 /user:10.0.0.219\ITTest

REM Set locations
SET source = D:\SafetyLineVoiceMsg
Echo %source%

SET destination = \10.0.0.219\Test
Echo %destination%
SET finallocation = z:
Echo %finallocation%

REM Move files older than x days to another folder.
robocopy %source% %destination% /MOV /COPYALL /MAXAGE:10 /R:5 /W:30 /LOG+:log.txt

REM Take those files and zip them up. (name zipped file with the date stamp).
7z a \10.0.0.219\Test\newFileName%date:~4,2%-%date:~7,2%-%date:~10%.7z @\l10.0.0.219\Test\files_to_backup.txt
move \10.0.0.219\Test*.* z:\

REM Delete the files that just got zipped.
DELTREE /Y %desitination%

REM Move Zipped files to another directory.
MOVE /Y %destination% %finallocation%

Is there any of above script still incorrectly typed or something?

log.txt (26.4 KB)

Please, after every change you make and test, paste the entire script in, and also the error message you received.
Otherwise we can’t tell what is wrong
Other than that, your net use line looks wrong. The format of net use is [net use] (optional drive letter) [path] (optional user) (optional password)
E.g.

Net use x: \server1\share1 /user:contoso\james mypassword
Or
Net use \server1\share1 /user:james
Etc

Here is my recent script that i have modified and still getting an error, check it:

REM Set Destination Login Authentication

net use c: \10.0.0.219\Test /user:10.0.0.219\ITTest Tsunami247

REM Set locations

SET source = D:\SafetyLineVoiceMsg
Echo %source%

SET destination = \10.0.0.219\Test
Echo %destination%

SET finallocation = z:
Echo %finallocation%

REM Move files older than x days to another folder.

robocopy %source% %destination% /MOV /COPYALL /MAXAGE:10 /R:5 /W:30 /LOG+:log.txt

REM Take those files and zip them up. (name zipped file with the date stamp).

7z a \10.0.0.219\Test\newFileName%date:~4,2%-%date:~7,2%-%date:~10%.7z @\10.0.0.219\Test\files_to_backup.txt
move \10.0.0.219\Test*.* z:\

REM Delete the files that just got zipped.

DELTREE /Y %desitination%

REM Move Zipped files to another directory.

MOVE /Y %destination% %finallocation%

and I don’t understand with your previous post. Which part or which lines contain that symbol I need to remove?

log.txt (27.3 KB)

Hi Gindo

Please post only the most recent log

2 Spice ups

You can’t map a network path to an existing drive letter.

Seems like you are very inexperienced with Windows - please follow this recommendation:

Before trying to add any line of code or command to your batch file, test it yourself first in the command prompt. that way you can see if the command is throwing any errors, and deal with them first.

e.g. if you are trying to map a network path in your script, first test the command by going

Start > Run > cmd

then manually type in your command “net use… etc” and you will see if it shows any errors. Do this for every command first.

The principle of batch coding, since it has no debugger, is to make only 1 change at a time, otherwise it becomes nearly impossible to debug unless you are extremely experienced or familiar with the code.

1 Spice up

Hi all,

again so sorry if I really stupid about this batch scripting, but I am very need to make my script can be work properly as it should be. I already very frustrated right now as I don’t know who I can ask to help me solve this problem. I also already discussed with all of my classmates about this thing, but they’re also dont know how to get it works. Here I have attached my recent script that I recently modified. It works very well, but its only for files instead of multiple folders contains any files or empty. So, I need any suggestion from all of you guy how to make it can be work also for multiple folders+files. Thank you so much…

test.bat (941 Bytes)