Xcopy question

I'm adding a backup option to my context menu. I want to make it so that whatever directory I'm in I can right-click on a file or folder and have it backed up to a certain location. This is the command I have so far:

xcopy /e /s /h /k /y %1 D:\Backups\

My question is: How do I maintain the same directory structure? If I want to backup c:\docs how can I make sure that they are copied to d:\Backups\docs? As it is right now the "docs" subdirectory does not get copied. Of course, this is just an example.

Any ideas?

At the command prompt type in: xcopy /h

this will list all the available parameters it can use.

Basically you're missing one of the following:

/S Copies directories and subdirectories except empty ones.
/E Copies directories and subdirectories, including empty ones.

Same as /S /E.

Edit: Oops just noticed you're already using /e /s.

At the command prompt type in: xcopy /h

this will list all the available parameters it can use.

Basically you're missing one of the following:

Edit: Oops just noticed you're already using /e /s.

Yeah t's a bit tricky. This command will copy *.* from a folder I right-click on including subdirectories but it will not create the main directory; the "docs folder does not get created upon backup, just everything inside the folder.

Have you tried your parameter with quotes around %1 and your directory, so that it would become:

xcopy /e /s /h /k /y "%1" "D:\Backups\"

Have you tried your parameter with quotes around %1 and your directory, so that it would become:

xcopy /e /s /h /k /y "%1" "D:\Backups\"

No luck. It didn't work.

This is a long away around, but it seems to work -

1) Create a Backup.bat file in the C:\WINDOWS\System32 folder -

===========================

@echo off&setlocal enableextensions

:: retrieving name of current directory

for %%* in (.) do set MyDir=%%~n*

:: adding safety factor for no directory, i.e a drive

if not defined MyDir set MyDir=%CD:\=%

:: telling you what it is

echo/ the current directory is %MyDir%

C:\WINDOWS\system32\xcopy.exe /e /s /h /k /y /i %1 E:\Test\%MyDir%

::pause

endlocal

===============

Notes:

a) remove the two full colons preceding pause and the command prompt window will stay open to observe the process

B) E:\Test is the destination folder for the copied files/folders - change for your local destination drive/folder

c) I think that piping could be added to create a log file of the xcopy command -

=====================

Echo. >>log.txt

echo.---------------------------------- >>log.txt

echo %date% %time% >>log.txt

echo.---------------------------------- >>log.txt

Echo. >>log.txt

C:\WINDOWS\system32\xcopy.exe /e /s /h /k /y /i %1 E:\Test\%MyDir% >> log.txt

===========================

I got the current directory retrieval idea from this link

http://www.msfn.org/board/topic/56320-retrieve-current-directory-name-in-batch/

2) Then create a Tools|Folder option|File type "Folder"|Advanced|New

Action: Backup

Application used to perform this action: C:\WINDOWS\system32\Backup.bat

Like I said, a long way around, but it greatly simplifies using Xcopy to make backups of selected files & folders

This thread is almost six years old.

Thanks, I guess though.

A moderator will probably lock this now though.

The important thing is, anyone googling this problem now can find an answer! :)