Run bat option with right click menu
#1
Posted 21 January 2010 - 07:52 AM
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
#2
Posted 21 January 2010 - 09:47 AM
No guarantees of course but, without the contents we can't be sure.
#3
Posted 21 January 2010 - 10:14 AM
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
Posted 21 January 2010 - 10:46 AM
right click
#5
Posted 21 January 2010 - 03:50 PM
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
Posted 22 January 2010 - 02:50 AM
Thanks for your input , I gather from your reply that you are thinking about it and will get back to me.
thanks
#7
Posted 23 January 2010 - 09:27 AM
#8
Posted 23 January 2010 - 09:53 AM
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:
Quote
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?
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
Posted 24 January 2010 - 03:48 AM
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
Posted 24 January 2010 - 03:58 AM
Purge.reg
Quote
[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.
This post has been edited by MrJinje: 24 January 2010 - 04:45 AM
#11
Posted 24 January 2010 - 08:28 AM
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
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
This post has been edited by jaclaz: 24 January 2010 - 08:35 AM
#12
Posted 25 January 2010 - 02:40 AM
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
Posted 25 January 2010 - 04:42 AM
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>NULBeware, right clicking on the incorrect folder will likely contribute to deleting several important files!
Attached File(s)
-
PurgeKey.zip (345bytes)
Number of downloads: 6



Help
Back to top









