safe delete files command

Jan 13, 2013
27
0
I wrote a simple batch file I call drydel.btm

echo off
rem drydel means dry run for del command
rem
dir %1$
INKEY /k"YN" del? %%ans
IFF %ans EQ Y THEN
del %1$
ENDIFF

I would like to make this behave like a command, that is, not have to be in the directory I want to use it in. What is the best way for me to do this?

Thx
 
Actually you don't need to be in the directory where you want to delete:
Code:
DRYDEL other\file.a
must work.
If you want to delete several files in the same directory you can use "include lists"
Code:
DRYDEL other\first.a;second.b
To improve the script you could add a test after DIR so that drydel exits if the files don't exist.
There are also alternatives without script
Code:
DEL /P other\first.a;second.b
SELECT DEL [other\first.a;second.b]
 
Jan 13, 2013
27
0
I thought of those. I was hoping it would be easy, like it was in bash. For bash, I wrote a function and placed it into my .bashrc file.

I thought that function would work that way her also. I read the help file and did not understand it to work that way. I tried defining a function in tcc but it did not work. I guess I don't understand function in the tcc sense. I was expecting bash capability.

As a side note, I'm sure others have also read that Win10 is getting bash this summer. This interests me also.
 
I don't know if I understand what exactly is troubling you. Your mentioning a function in .bashrc could mean that you want to have this DRYDEL.BTM in one place and be able to access it from any directory.
I use to set up my systems with a D:\User\bin directory, where I put all my .BTMs, and have TCSTART.BTM (equivalent to .bashrc) with a line like
Code:
set PATH=D:\User\bin;%PATH
 
Jan 13, 2013
27
0
That's what I want to do. Thanks. I was making it more complex than it needed to be, it seems.
 
I wrote a simple batch file I call drydel.btm

echo off
rem drydel means dry run for del command
rem
dir %1$
INKEY /k"YN" del? %%ans
IFF %ans EQ Y THEN
del %1$
ENDIFF

I would like to make this behave like a command, that is, not have to be in the directory I want to use it in. What is the best way for me to do this?

Thx
One way would be to define an alias that points to DryDel.btm:
ALIAS DRYDEL=`*<drydel's location>\DRYDEL.BTM`

-- Howard
 
Jan 13, 2013
27
0
I tried that but got a file not found error. Why does your alias begin with * ? I did not do that.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,689
106
Albuquerque, NM
prospero.unm.edu
Incidentally, it seems you can't use the * prefix after the ? command:
Code:
?*del foobar
gives an "Unknown command" error if you hit Y at the prompt.

Do I win the coveted prize for "Most Antique Bug Ever Reported"?
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,689
106
Albuquerque, NM
prospero.unm.edu
I tried that but got a file not found error. Why does your alias begin with * ? I did not do that.

The asterisk prevents alias expansion on the following command. It's almost certainly not necessary in this case -- you're not gonna have an alias name matching the name of your batch file. This feature is most useful if you're using aliases to intercept internal commands, an advanced and potentially confusing technique.
 
Jan 13, 2013
27
0
That does what I want. I'm glad I posted. I made it
alias drydel=`del /n %$ & if %_del_files GT 0 ?del %$`

Thanks guys
 

Similar threads