Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch Script, right click, directory

Status
Not open for further replies.

Aurillius

Programmer
Jun 3, 2004
60
CA
Hi guys,
I would like to find out how to create a right click selection pointing to a batch file, while running within the folder that has been selected (much like nature of the "Open Command Window here" option but with a .bat file executed following).

Thanks,
Aurillius
 
First of all you would need to create the bat file. to do what you want. Keeping in mind that the "%1" variable will hold the directory path when it is run. So if say you wanted to list the directory for it you would issue the command
Code:
dir %1
in the bat file.

Once the bat file is done.

Open Windows Explorer to any folder and go to tools Folder Options, Select the File Types Tab. And then you'll want to click on Folder and File Folder types and do the following on each.

Click Advanced-> then click on New to add a new action for the type. Give it a name, (that's the one that will appear on the right click menu) and add your BAT file to it.

[red]NOTE:Be careful to do it right the first time as you wont be able to remove it afterwards unless you go into the Registry and alter the type there.[/red]

Do the same for both types. and o.k your way out.

Right click on any folder and you should have a new Action as defined by you.

[red]Warning: If for some strange reason you loose the ability to open the folders by double clicking them and instead get the Search companion. Do the following to restore it:[/red]

That should maintain the new option in the Right click menu, and the Folder should work normally.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I almost have it but still need help.

I need the first part to execute like the "open here..." command in the sense of opening a dos window in the selected folder, leaving it open, and executing the batch file within the current directory.

eg: cmd.exe /k "cd %L"-------> then .bat file

...but I want to execute a batch file on somewhere else within the folder right clicked.

I know the syntax is wrong here but I was using:

' cmd.exe /k "cd %L" "c:\w.bat" ' on the registry key.

The batch file has the right instructions and if I run it anywhere by typing "c:\w.bat" it runs within that folder.

What do I change in the key?
 
First of all loose the cmd.exe at the beginning. When you run the bat file it will automatically open the command prompt session, no need to call cmd.exe, and be placed in the folder you called it from.

Second if you want to run something else somewhere else, just issue the command to change the location to the folder you want to run it from and then run it.

so say you call the batch file form C:\Myfolder. And you want to execute something there and then something in another folder like C:\myotherfolder\.

The batch file gets called form within C:\myfolder



do something in initial location...
cd\ [green]\\Changes back to root drive[/green]
cd myotherfolder's_Path [green]\\Changes to other folder[/green]
do something else
example:
Code:
copy afile.txt C:\myotherfolder
cd\
cd myotherfolder
rename afile.txt otherfile.txt

this would copy afile.txt to myotherfolder and then go in and rename it.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top