Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

Run bat option with right click menu


  • Please log in to reply
12 replies to this topic

#1
kenppy

kenppy
  • Member
  • 8 posts
  • Joined 21-January 10
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


How to remove advertisement from MSFN

#2
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,540 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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.

#3
kenppy

kenppy
  • Member
  • 8 posts
  • Joined 21-January 10
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

#4
kenppy

kenppy
  • Member
  • 8 posts
  • Joined 21-January 10
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

#5
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,540 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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.

#6
kenppy

kenppy
  • Member
  • 8 posts
  • Joined 21-January 10
Yzöwl,

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

#7
kenppy

kenppy
  • Member
  • 8 posts
  • Joined 21-January 10
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?

#8
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,564 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
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.codeproje...appendmenu.aspx
http://windowsxp.mvp...ext_folders.htm

jaclaz

#9
kenppy

kenppy
  • Member
  • 8 posts
  • Joined 21-January 10
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

#10
MrJinje

MrJinje

    Tool™ Developer

  • Developer
  • 1,051 posts
  • Joined 14-October 09
  • OS:Server 2012R2
  • Country: Country Flag
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, 24 January 2010 - 04:45 AM.


#11
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,564 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
@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...iate/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, 24 January 2010 - 08:35 AM.


#12
kenppy

kenppy
  • Member
  • 8 posts
  • Joined 21-January 10
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!

#13
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,540 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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!

Attached Files






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users