Page 1 of 1

Context Menu Backup [REGEDIT AND BATCH]

Posted: 02 Dec 2012 06:27
by Boombox
.
My goal is to have a right-click context-menu-item called 'BACKUP'...
Every file and folder, when right clicked, will have access to this menu item.
And each item will be sent to the same location. D:\MUSTSAVE\

USING REGEDIT

Navigate to HKEY_CLASSES_ROOT\*\SHELL

Right click 'shell' and choose 'New' then 'Key'.

Rename this key to 'BACKUP'

Inside this key I create another key called 'command'.

With the 'command' key selected, edit the '(Default)' string by double clicking (right pane).

In the blank field I reference the name of my batch file and any parameters

I used,
c:\save.bat %1

To apply this to folders, navigate to HKEY_CLASSES_ROOT\DIRECTORY\SHELL and create the same keys.

Now, I know that the command needs to differ, depending on the backup item. (Item or folder).

So I added a parameter to the 'BACKUP' string in the 'Directory' location. I simply used the word 'folder'.

c:\save.bat %1 folder

My c:\Save.bat contained:

Code: Select all

if %2==folder goto robo

if not exist d:\MUSTSAVE md d:\MUSTSAVE
copy "%1" "d:\MUSTSAVE\%~nx1"
pause

:robo
if not exist d:\MUSTSAVE md d:\MUSTSAVE
robocopy %1 d:\MUSTSAVE\%~nx1
pause


Robocopy handles the folders fine, but if %2 is not equal to 'folder' the bat just exits.

Can someone help me please. Thanks.

Re: Context Menu Backup [REGEDIT AND BATCH]

Posted: 02 Dec 2012 06:43
by foxidrive
Boombox wrote:Robocopy handles the folders fine, but if %2 is not equal to 'folder' the bat just exits.


Try this:

if "%~2"=="folder" goto robo


Also add a /b to the copy command.

and a goto :EOF after the copy command by the looks of it.

Your copy command will fail if %1 is quoted - I think you need to take another look at it. :)

Re: Context Menu Backup [REGEDIT AND BATCH]

Posted: 02 Dec 2012 06:55
by foxidrive
if %2==folder goto robo

if not exist d:\MUSTSAVE md d:\MUSTSAVE
copy "%1" "d:\MUSTSAVE\%~nx1"
pause

:robo
if not exist d:\MUSTSAVE md d:\MUSTSAVE
robocopy %1 d:\MUSTSAVE\%~nx1
pause


Try this instead:

@echo off
if not exist "d:\MUSTSAVE\" md "d:\MUSTSAVE"
if "%~2"=="folder" (
robocopy "%~1" "d:\MUSTSAVE\%~nx1\"
) else (
copy /b /z "%~1" "d:\MUSTSAVE\"
)
pause

Re: Context Menu Backup [REGEDIT AND BATCH]

Posted: 02 Dec 2012 07:49
by Boombox
.
@echo off
if not exist "d:\MUSTSAVE\" md "d:\MUSTSAVE"
if "%~2"=="folder" (
robocopy %1 d:\MUSTSAVE\%~nx1
) else (
copy /b /z "%~1" "d:\MUSTSAVE\"
)
pause

This worked for me with the above line void of quotes.

Thanks a bunch Foxi.

Re: Context Menu Backup [REGEDIT AND BATCH]

Posted: 02 Dec 2012 09:08
by foxidrive
Boombox wrote:.
This worked for me with the above line void of quotes.

Thanks a bunch Foxi.


That's ok. When all things are equal it will not work when there are spaces in the foldername though.