• Announcements

    • xper

      MSFN Sponsorship and AdBlockers!   07/10/2016

      Dear members, MSFN is made available via subscriptions, donations and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, become a site sponsor and ads will be disabled automatically and by subscribing you get other sponsor benefits.
Sign in to follow this  
Followers 0
kenppy

Run bat option with right click menu

13 posts in this topic

Hello

I have a batch file that cleans up any picked directory [removes files with specified extensions]

In XP I had it such that I picked a directory, RMB and chose the action.

The instructions to install this facility were: open any directory tools/ folder options.. /file types/file folder/advanced/new...

In Action type<name facility>, In Application used to perform action browse to location of batch file.

Now in Windows7 these instructions don't seem to apply as stuff is in different places. I can make the facility work by placing the batch file in a directory and running it, but this leaves the batch file to be removed and nothing as easy as it was.

Can anyone point to how to do this?

thanks

0

Share this post


Link to post
Share on other sites

Paste the contents of the batch file here and we may be able to provide a context menu entry without the need for the batch file.

No guarantees of course but, without the contents we can't be sure.

0

Share this post


Link to post
Share on other sites

I'm using ProEngineer which generates many report and log files which need to be deleted in order to tidy up the folder. The last line calls for a subroutine which tidies up the sequentially generated model files, we can ignore this for the moment, it will be good to get the body of the batch file to work first. I have run this without the last line in case that was the problem, it wasn't.

As I said, this fully works in XP but not W7.

tidy.bat

CD "%1 %2 %3 %4 %5 %6 %7 %8 %9"

echo y | del *.crc.*

echo y | del *.log.*

echo y | del *.m_p.*

echo y | del *.ger.*

echo y | del *.inf.*

echo y | del *.lst.*

echo y | del *.log

echo y | del *.plt

echo y | del *.idx

echo y | del *.tst

C:\Program Files\proeWildfire 4.0\bin\purge.bat

0

Share this post


Link to post
Share on other sites

Also helpful might be this reference where I first learnt how to add the right menu function, but as I said, these instructions cannot be followed in W7.

right click

0

Share this post


Link to post
Share on other sites

Firstly I'd like to make some code observations:

Bat files are long outdated, cmd files were introduced with the Windows NT family.

When using CD the /D switch should really be invoked.

Changing directory to one containing spaces does not require 'double quotes'.

DEL has a built in /Q switch.

The DEL command accepts multiple arguments on one line.

0

Share this post


Link to post
Share on other sites

Yzöwl,

Thanks for your input , I gather from your reply that you are thinking about it and will get back to me.

thanks

0

Share this post


Link to post
Share on other sites

I'm not really into using code at this level, what are you suggesting this file should look like to work. I don't understand why batch files are outdated the cad package I have is full of bat filesand this is the latest cut for win7?

0

Share this post


Link to post
Share on other sites

I guess that what Yzöwl was saying is that .bat files are a "historical" remnant of DOS/Win9x, since NT batch scripts use a "better" engine (cmd.exe instead of command.com) and should (though not compulsory) use the .cmd extension.

The snippet you posted does not make much sense (to me at least), what is the scope of the CD %1 %2 etc? to get a directory name including spaces?

The DEL command when used in a batch does NOT need for confirmation so the whole point of feeding to it through ECHO a "y" is pointless.

I would write this:

CD "%1 %2 %3 %4 %5 %6 %7 %8 %9"

echo y | del *.crc.*

echo y | del *.log.*

echo y | del *.m_p.*

echo y | del *.ger.*

echo y | del *.inf.*

echo y | del *.lst.*

echo y | del *.log

echo y | del *.plt

echo y | del *.idx

echo y | del *.tst

as

CD /D %*
FOR %%? IN (
.crc.
.log.
.m_p.
.ger.
.inf.
.lst.
.log
.plt
.idx
.tst
) DO DEL *%%?*

If I get it right you want to add it to a contextual menu for the object "Folder" or am I mistaken? :unsure:

I think that on 7 the add a context menu entry in Registry hasn't changed:

http://www.codeproject.com/KB/cs/appendmenu.aspx

http://windowsxp.mvps.org/context_folders.htm

jaclaz

0

Share this post


Link to post
Share on other sites

Hi jaclaz,

I'm a newbie with computers at the coding level. The batch file deletes files with those extensions from a picked directory. The code I posted was written by another and when used on my XP machine and it worked through the right context menu.

Now that I've migrated to windows7 the only way I can get this to work is to copy the batch file directly into the directory to be cleaned and double clicking it in explorer. What I couldn't do is to run it through rc menu. So I didn't question the the code as it worked.

I've made a file with your code called clean1.bat and run it and that does the same as my original. Curiously it also works when called clean1.cmd. I guess you'll be able to tell me why that is.

The problem then reverts to where I started, how do I find a painless way to get this into the right context menu for windows7?

thanks

0

Share this post


Link to post
Share on other sites

This will add your Purge.bat to your right click entry on all folders. Adjust as needed, not sure if you wanted to use Tidy.bat or Purge.bat, but this is what I guessed from your post.

Purge.reg

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Folder\shell\Purge\Command]

@="C:\\Program Files\\proeWildfire 4.0\\bin\\purge.bat"

EDIT: I added the extra \\ on purpose, be sure to include them if you edit the .reg file directly.

Edited by MrJinje
0

Share this post


Link to post
Share on other sites

@kenppy

As said on NT based OS .bat or .cmd is the same, .bat is considered "outdated" and .cmsd is advised, this is because NT based systems do execute BOTH .bat and.cmd whilst DOS/9x/Me systems ONLY execute.bat files. Since the syntax can be different it's a form of "security" setting that avoids a batch file created for NT systems to run on 9x/Me ones.

MrJinje has kindly explicited :), adapting the procedure to your case, what you should have found by yourself had you read the links I gave you.

Basically in the Registry there are settings for the "riight click" or "context menu" for each "kind" of object, among which the "Folder" one, that can be customized.

What the procedure you described did in XP was simply that of adding this settings in the Registry.

The links I gave you explain the basics and a small program that should replicate the behaviour.

What MrJinje posted is a way to have these settings entered in the Registry by using a .reg file that you can "merge" to the Registry.

Another app is Wassociate:

http://www.xs4all.nl/~wstudios/Associate/index.html

(though cannot say it works with 7, it's site and help further explain the way this associations work)

A small note:

a batch file by default can "index" only 9 parameters passed to it:

%1

%2

%3

%4

%5

%6

%7

%8

%9

thus should for any reason the folder you have be "nested" in a path with more than 8 spaces, like:

C:\My Programs\whatever main program\the specific program title\data files\main data directory\

the original batch won't work.

By using %* instead you get ALL parameters.

The added /D to the CD command allows to change Drive, without it the original batch will work only if the directory is on current drive.

jaclaz

Edited by jaclaz
0

Share this post


Link to post
Share on other sites

Hi all,

Thanks for your input, I'll have to read up and try to understand this stuff before I continue. I don't want to have started looking for a shortcut and ended with a mess!

0

Share this post


Link to post
Share on other sites

Okay, here's what I'd do!

Below you'll find some code, (it's also zipped up in an attachment just to make sure you don't make copy & paste mistakes).

It is all you need, no additional batch files etc.

Just double click this one and you'll have a new entry in your right click menu, Purge Files.

PurgeKey.cmd

@ECHO OFF & SETLOCAL
SET "STARTKEY=HKCU\Software\Classes\"
SET "ENDKEY=\shell\PurgeMe"
REG ADD %STARTKEY%Folder%ENDKEY% /VE /D "Purge &Files" /F>NUL
REG ADD %STARTKEY%Folder%ENDKEY%\command /VE /T REG_EXPAND_SZ /D^
"%%COMSPEC%% /C PUSHD %%L && DEL *.crc.* *.log.* *.m_p.* *.ger.* *.inf.* *.lst.* *.plt *.idx *.tst" /F>NUL

Beware, right clicking on the incorrect folder will likely contribute to deleting several important files!

PurgeKey.zip

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.