0

I want to run a centrally stored batch file from a right click context menu, but the batch file needs to change its' relative location (%~dp0) reference to where the user right clicked instead of the location of the batch file.

So basically I need this sequence to work...

1) When a user selects an option from a Right Click context menu in File Explorer, the folder they are in is set as a variable

2) A batch file is started and uses the location variable set in step 1 for the work being performed...

I know the batch code for doing the work I want done (creating new folders) and I am able to create a registry entry for the right click context menu, I just don't know how to pass the folder location the user right clicked in as a variable to use in the batch file.

Thoughts? Would PowerShell be a better option?

1 Answer 1

1

I figured it out....

1) Registry entry to setup the right click context option..

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\Create Client Folders]
@="&Create Client Folders"
"Icon"="%SystemRoot%\\System32\\shell32.dll,71"

[HKEY_CLASSES_ROOT\Directory\Background\shell\Create Client Folders\command]
@="DRIVELETTER:\\FOLDER\\batch_file_name.bat \"%V\""
  1. In Batch file, use %cd% to get the right click location (this is only when clicking in the open "white space" of a folder,,, not on a folder itself... my example batch file to create folders based on contents of text file...

set TheRoot=%cd%

for /F "tokens=1 delims=," %%d IN (DRIVELETTER:\FOLDER\TextFileName.txt) DO md "%TheRoot%\%%d"

The text file is just a return delimited file with folder names

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .