JSI Tip 7125. How can I configure an Explorer right-click to copy a file to one or more destination folders?


If you require the ability to have a right-click context menu item copy a selected file to one or more destination folders, and the ability to have different destination folders based upon the source folder, or based upon the source folder and file extension, BkpFile.bat may provide a solution.

The solution in this script requires:

1. A BkpFile registry key, with command sub-key, for each file extension that the context menu will be available for. I have provided BkpFileCFG.bat to set the registry entries for the extensions that you specify. To configure the BkpFile right-click context menu for .doc, .xls, and .pdf extensions, run
BkpFileCFG .doc .xls .pdf

NOTE: BkpFileCFG.bat uses Reg.exe from the Windows 2000 Support Tools, or Reg.exe that is built into Windows XP and later.

NOTE: If you do not wish to configure extensions, create a Minimized shortcut to BkpFile.bat in your SendTo folder.

2. A BkpFile.cfg file must be present in every source folder, to specify the one or more destination folders, for all or a specified file extension. The syntax of a record in the BkpFile.cfg file is:

Ext Destination

where Ext is a file extension, or * for any extension, and Destination is the full path to the destination folder for files with the Ext extension. Multiple records are permitted.

Example: To configure that any extension in the source folder should be copied to D:\folder1 and E:\folder2 and to cause .doc extensions in the source folder to also be copied to K:\folder3, the BkpFile.cfg file in this source folder would contain:

* d:\folder1
* E:\folder2
.doc K:\folder3

NOTE: Quote marks are NOT required, but may be present, for destination folders that contain spaces.

3. The BkpFile.bat file must be stored as %SystemRoot%\BkpFile.bat.

NOTE: If you use the SendTo folder, instead of configuring extensions, you can place the BkpFile.bat anywhere, as the shortcut will point to it.

The BkpFileCFG.bat registry configuration script contains:

@echo off
if \{%1\}

\{\} @echo Syntax BkpFileCFG EXT1 \[EXT2 EXT3 .... EXTn\] setlocal @echo REGEDIT4>"%TEMP%\BkpFileCFG.TMP" @echo.>>"%TEMP%\BkpFileCFG.TMP" :loop if \{%1\}

\{\} goto finish set ext=%1 if not "%ext:~0,1%" EQU "." set ext=.%ext% set key=N for /f "Tokens=4" %%k in ('reg query HKCR\%ext% /ve') do set key=%%k if "%key%" EQU "N" @echo BkpFileCFG did not find HKCR\%ext% in the registry.&goto next @echo \[HKEY_CLASSES_ROOT\%key%\shell\BkpFile\command\]>>"%TEMP%\BkpFileCFG.TMP" @echo @=hex(2):25,53,79,73,74,65,6d,52,6f,6f,74,25,5c,42,6b,70,46,69,6c,65,2e,62,61,\>>"%TEMP%\BkpFileCFG.TMP" @echo 74,20,22,25,31,22,00>>"%TEMP%\BkpFileCFG.TMP" @echo.>>"%TEMP%\BkpFileCFG.TMP" :next shift goto loop :finish @echo.>>"%TEMP%\BkpFileCFG.TMP" regedit /s "%TEMP%\BkpFileCFG.TMP" del /q "%TEMP%\BkpFileCFG.TMP" endlocal
The BkpFile.bat script, which is invoked when you right-click a file and press BkpFile, contains:
@echo off
setlocal
set file=%1
set dp=%~dp1
set ext=%~x1
set OK=N
pushd "%dp%"
for /f "Tokens=1*" %%c in ('type bkpfile.cfg') do set cfgext=%%c&set copyto=%%d&call :parse
if "%cfgext%"=="" set OK=X&net send %computername% %dp%bkpfile.cfg is missing.
if "%OK%" EQU "N" net send %computername% %dp%bkpfile.cfg has not valid entries.
popd
endlocal
goto :EOF
:parse
set copyto=%copyto:"=%
if "%cfgext%" EQU "*" copy %file% "%copyto%\*.*"&set OK=Y&goto :EOF
if "%cfgext%" EQU "%ext%" copy %file% "%copyto%\*.*"&set OK=Y



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish